Java tutorial
//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 "); } buff.append(object); if (i < (size - 1)) { if (size > 2) { buff.append(", "); } else { buff.append(" "); } } i++; } return buff.toString(); } }