public class JavaCode { public String toJSON(Collection collection) { StringBuilder sb = new StringBuilder(); sb.append("["); Iterator iterator = collection.iterator(); while (iterator.hasNext()) { Integer element = iterator.next(); sb.append(element); if (iterator.hasNext()) { sb.append(", "); } } sb.append("]"); return sb.toString(); } }