Here you can find the source of toString(Collection
public static <T> String toString(Collection<T> collection)
//package com.java2s; import java.util.Collection; public class Main { public static <T> String toString(Collection<T> collection) { StringBuilder stringBuilder = new StringBuilder("["); boolean first = true; for (T t : collection) { if (!first) { stringBuilder.append(','); } else { first = true;//from ww w .j ava 2 s.co m } if (t == null) { stringBuilder.append("null"); } else { stringBuilder.append(t.toString()); } } stringBuilder.append(']'); return stringBuilder.toString(); } }