Here you can find the source of collectionToString(Collection> c, String separator)
public static String collectionToString(Collection<?> c, String separator)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Iterator; public class Main { public static String collectionToString(Collection<?> c, String separator) { Iterator<?> i = c.iterator(); StringBuffer sb = new StringBuffer(); boolean isNext = false; while (i.hasNext()) { if (isNext) { sb.append(separator);//from w w w . j a v a2s . c om } else { isNext = true; } sb.append(i.next()); } return sb.toString(); } }