Here you can find the source of listToString(Collection
public static String listToString(Collection<String> l)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Iterator; public class Main { public static String listToString(Collection<String> l) { StringBuffer result = new StringBuffer(); if (l != null) { Iterator<String> iter = l.iterator(); while (iter.hasNext()) { String s = (String) iter.next(); result.append(s);//from ww w .jav a 2 s. c o m if (iter.hasNext()) { result.append(","); } } } return result.toString().trim(); } }