Here you can find the source of join(final Collection
Parameter | Description |
---|---|
collection | a parameter |
delimiter | a parameter |
public static <T> String join(final Collection<T> collection, final String delimiter)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { /**// ww w . j av a 2 s . co m * A method for joing together a collection of strings using a specified * delimiter. * * @param collection * @param delimiter * @return */ public static <T> String join(final Collection<T> collection, final String delimiter) { if (collection == null || collection.isEmpty()) { return ""; } Iterator<T> it = collection.iterator(); StringBuffer buffer = new StringBuffer(it.next().toString()); while (it.hasNext()) { buffer.append(delimiter).append(it.next().toString()); } return buffer.toString(); } }