Here you can find the source of join(Collection> stringList, String seperator)
public static String join(Collection<?> stringList, String seperator)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.Map; public class Main { public static String join(Collection<?> stringList, String seperator) { return join(stringList, seperator, "%s"); }/* www .j a va2 s . co m*/ public static String join(Collection<?> stringList, String seperator, String itemFormat) { StringBuffer buffer = new StringBuffer(); Iterator<?> it = stringList.iterator(); for (int i = 0; it.hasNext(); i++) { if (i > 0) { buffer.append(seperator); } buffer.append(printf(itemFormat, it.next().toString())); } return buffer.toString(); } public static String printf(String format, Object... args) { return String.format(format, args); } public static String toString(Collection<?> itemList) { return printf("[%s]", join(itemList, ", ", "\"%s\"")); } public static String toString(Map<?, ?> itemMap) { ArrayList<String> entryStrings = new ArrayList<String>(); for (Map.Entry<?, ?> entry : itemMap.entrySet()) { String entryString = printf("%s: \"%s\"", entry.getKey(), entry.getValue()); entryStrings.add(entryString); } return printf("{%s}", join(entryStrings, ", ")); } }