Android examples for java.lang:String Join
Joins all items in the `collection` into a `string`, separated by the given `delimiter`.
import java.util.Collection; import java.util.Iterator; public class Main{ /**/*from w ww. j a v a 2s .c o m*/ * Joins all items in the `collection` into a `string`, separated by the given `delimiter`. * * @param collection * the collection of items * @param delimiter * the delimiter to insert between each item * @return the string representation of the collection of items */ public static String join(Collection<?> collection, String delimiter) { if (collection == null) return ""; StringBuilder buffer = new StringBuilder(); Iterator<?> i = collection.iterator(); while (i.hasNext()) { buffer.append(i.next()); if (i.hasNext()) { buffer.append(delimiter); } } return buffer.toString(); } }