Convert list of string To a single String with passed in separator - Android java.lang

Android examples for java.lang:String Join

Description

Convert list of string To a single String with passed in separator

Demo Code

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.widget.TextView;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class Main{

    public static String listToString(List<String> stringList, String split) {
        if (stringList == null || stringList.size() <= 0 || split == null) {
            return null;
        }//from ww  w .j  av  a 2 s.c o  m
        StringBuilder result = new StringBuilder();
        boolean flag = false;
        for (String string : stringList) {
            if (flag) {
                result.append(split);
            } else {
                flag = true;
            }
            result.append(string);
        }
        return result.toString();
    }

}

Related Tutorials