Here you can find the source of listToStr(Collection
public static <TypeName> String listToStr(Collection<TypeName> c, String delim)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { public static <TypeName> String listToStr(Collection<TypeName> c, String delim) { StringBuilder sb = new StringBuilder(); int a = 0; for (Iterator<TypeName> i = c.iterator(); i.hasNext();) { TypeName s = i.next();//from w w w . java 2 s. c o m sb.append(s); if (++a >= c.size()) break; sb.append(delim); } return sb.toString(); } }