Creates concatenation of all strings provided, additionally adding given separator between each concatenation. - Android java.lang

Android examples for java.lang:String Join

Description

Creates concatenation of all strings provided, additionally adding given separator between each concatenation.

Demo Code

import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

public class Main{

    /**/*  w  w  w. ja va2s.  com*/
     * Creates concatenation of all strings provided, additionally adding
     * given separator between each concatenation.
     *
     * @param strings List of string to merge.
     * @param separator Separator to use.
     * @return The concatenated string.
     */
    public static String getConcatenatedString(List<String> strings,
            String separator) {
        String sep = getNotNull(separator);
        StringBuilder stringBuilder = new StringBuilder();
        if (strings != null) {
            int size = strings.size();
            for (int i = 0; i < size; ++i) {
                if (stringBuilder.length() > 0) {
                    stringBuilder.append(sep);
                }
                stringBuilder.append(strings.get(i));
            }
        }
        return stringBuilder.toString();
    }

}

Related Tutorials