Here you can find the source of toString(Collection> itemList)
public static String toString(Collection<?> itemList)
//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 toString(Collection<?> itemList) { return printf("[%s]", join(itemList, ", ", "\"%s\"")); }//from ww w . j a v a 2 s . c o m 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, ", ")); } public static String printf(String format, Object... args) { return String.format(format, args); } public static String join(Collection<?> stringList, String seperator) { return join(stringList, seperator, "%s"); } 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(); } }