join string from object list - Android java.lang

Android examples for java.lang:String Join

Description

join string from object list

Demo Code

import java.util.List;

public class Main{

    public static String join(List<?> texts, String separator) {
        StringBuilder result = new StringBuilder();
        for (Object text : texts) {
            result.append(text);//from  w  w  w. ja v a 2 s .c om
            result.append(separator);
        }
        return result.toString();
    }
    public static String join(String separator, Object... texts) {
        StringBuilder result = new StringBuilder();
        boolean isFirst = true;
        for (Object text : texts) {
            if (isFirst) {
                result.append(separator);
                isFirst = false;
            }
            result.append(text);
        }
        return result.toString();
    }

}

Related Tutorials