Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static String toString(Collection coll) { return toString(coll, ", "); } public static String toString(Collection coll, String delim) { StringBuffer sb = new StringBuffer(); for (Iterator it = coll.iterator(); it.hasNext();) { Object obj = it.next(); sb.append(String.valueOf(obj)); if (it.hasNext()) { sb.append(delim); } } return sb.toString(); } }