Android examples for java.lang:StringBuilder
join collections and object array by delimiter and StringBuilder
import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.regex.Pattern; public class Main{ public static String join(String delimiter, Collection<?> segments) { StringBuilder stringBuilder = new StringBuilder(); if (segments != null) { appendCollectionObjectToStringBuilder(stringBuilder, delimiter, segments);// w w w .j a v a 2s.c om } String outString = stringBuilder.toString(); if (outString.endsWith(delimiter)) { return outString.substring(0, outString.length() - delimiter.length()); } return outString; } public static String join(String delimiter, Object... segments) { StringBuilder stringBuilder = new StringBuilder(); if (segments != null) { int size = segments.length; if (size > 0) { for (int i = 0; i < size; i++) { appendObjectToStringBuilder(stringBuilder, delimiter, segments[i]); } } } String outString = stringBuilder.toString(); if (outString.endsWith(delimiter)) { return outString.substring(0, outString.length() - delimiter.length()); } return outString; } }