join list of string by separator - Android java.lang

Android examples for java.lang:String Join

Description

join list of string by separator

Demo Code

import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String join(ArrayList<Long> list, String separator) {
        String retStr = "";
        for (int i = 0, len = list.size(); i < len; i++) {
            if (i == 0) {
                retStr += list.get(i).toString();
            } else {
                retStr += separator + list.get(i).toString();
            }//from   ww  w  . j a  va  2 s.c  om
        }
        return retStr;
    }

}

Related Tutorials