Here you can find the source of collectionToString(Collection c)
public static String collectionToString(Collection c)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static String collectionToString(Collection c) { StringBuffer buff = new StringBuffer(); int i = 0; int size = c.size(); for (Iterator iter = c.iterator(); iter.hasNext();) { Object object = iter.next(); if (size > 1 && i == (size - 1)) { buff.append("and "); }/*from w w w.ja va2 s . com*/ buff.append(object); if (i < (size - 1)) { if (size > 2) { buff.append(", "); } else { buff.append(" "); } } i++; } return buff.toString(); } }