join set of string to a string - Android java.lang

Android examples for java.lang:String Join

Description

join set of string to a string

Demo Code

import android.util.Log;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Set;

public class Main{


    public static String join(Set<String> set, String delim) {
        if (set != null && delim != null) {
            StringBuilder sb = new StringBuilder();
            String loopDelim = "";

            for (String s : set) {
                sb.append(loopDelim);//from ww  w  .jav a  2  s.co m
                sb.append(s);

                loopDelim = delim;
            }

            return sb.toString();
        }
        return null;
    }

}

Related Tutorials