Here you can find the source of toString(Collection
public static <T extends Object> String toString(Collection<T> collection)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { public static <T extends Object> String toString(Collection<T> collection) { StringBuilder sb = new StringBuilder(); if (collection.size() == 0) { return ""; }/*from w w w .j a va 2 s. c o m*/ for (T object : collection) { sb.append(object.toString()); sb.append(","); } return sb.substring(0, sb.length() - 1); } public static <T extends Object> String toString(Collection<T> collection, String delim) { StringBuilder sb = new StringBuilder(); if (collection.size() == 0) { return ""; } for (T object : collection) { sb.append(object.toString()); sb.append(delim); } return sb.substring(0, sb.length() - 1); } }