Here you can find the source of toStringWithSeparator(Collection> collection, String separator)
public static String toStringWithSeparator(Collection<?> collection, String separator)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { public static String toStringWithSeparator(Collection<?> collection, String separator) {/*from ww w . j a va2 s . c om*/ if (collection.isEmpty()) return ""; StringBuilder b = new StringBuilder(); Iterator<?> it = collection.iterator(); while (true) { b.append(it.next()); if (it.hasNext()) { b.append(separator); } else { break; } } return b.toString(); } }