Here you can find the source of concatEntries(Collection> coll, String sep, String lastSep)
public static String concatEntries(Collection<?> coll, String sep, String lastSep)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { public static String concatEntries(Collection<?> coll, String sep, String lastSep) { if (lastSep == null) { lastSep = sep;//from w w w . jav a 2 s . c o m } int len = coll.size(); StringBuilder sb = new StringBuilder(16 + (len << 3)); Iterator<?> it = coll.iterator(); int i = 0; while (it.hasNext()) { if (i == 0) { ; } else if (i == (len - 1)) { sb.append(lastSep); } else { sb.append(sep); } ++i; sb.append(it.next()); } return sb.toString(); } }