Here you can find the source of toDelimitedString(Collection
public static String toDelimitedString(Collection<String> coll, String delim)
//package com.java2s; //License from project: LGPL import java.util.Collection; import java.util.Iterator; public class Main { public static String toDelimitedString(Collection<String> coll, String delim) { return toDelimitedString(coll, delim, "", ""); }//from ww w. ja v a 2 s.c o m public static String toDelimitedString(Collection<String> coll, String delim, String prefix, String suffix) { if (coll == null || coll.size() == 0) return ""; StringBuilder sb = new StringBuilder(); Iterator<String> it = coll.iterator(); while (it.hasNext()) { sb.append(prefix).append(it.next()).append(suffix); if (it.hasNext()) { sb.append(delim); } } return sb.toString(); } }