Android examples for java.lang:String Join
join Iterable<T> to string
import android.content.Context; public class Main{ public static <T> String join(Iterable<T> list, String separator) { StringBuilder sb = new StringBuilder(); String tempSeparator = ""; for (T o : list) { sb.append(tempSeparator).append(o); tempSeparator = separator;/*from ww w . ja v a2 s.co m*/ } return sb.toString(); } public static <T> String join(Iterable<T> list, String separator, int limitLen) { StringBuilder sb = new StringBuilder(); String tempSeparator = ""; for (T o : list) { if (sb.length() + tempSeparator.length() + o.toString().length() + 3 >= limitLen) { sb.append("..."); break; } sb.append(tempSeparator).append(o); tempSeparator = separator; } return sb.toString(); } }