join string list to a single string - Android java.lang

Android examples for java.lang:String Join

Description

join string list to a single string

Demo Code

import java.util.List;

public class Main{

    public static String join(List<String> list, String glue) {
        return join(list.toArray(new String[0]), glue);
    }/* w  w  w. jav  a2  s  .  c  o m*/
    public static String join(String[] s, String glue) {
        int k = s.length;
        if (k == 0)
            return null;
        StringBuilder out = new StringBuilder();
        out.append(s[0]);
        for (int x = 1; x < k; ++x)
            out.append(glue).append(s[x]);
        return out.toString();
    }

}

Related Tutorials