Here you can find the source of collectionToString(Collection> c)
public static String collectionToString(Collection<?> c)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static String collectionToString(Collection<?> c) { StringBuilder sb = new StringBuilder("["); Iterator<?> i = c.iterator(); while (i.hasNext()) { Object o = i.next();//from w ww . ja v a 2 s . com if (o == null) sb.append("null"); else if (o == c) sb.append("(this Collection)"); else sb.append(o.toString()); if (i.hasNext()) sb.append(", "); } sb.append("]"); return sb.toString(); } public static String toString(Object o) { return String.valueOf(o); } }