Here you can find the source of getCommaSeparatedListOfString( Collection
public static String getCommaSeparatedListOfString( Collection<String> list)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static String getCommaSeparatedListOfString(String[] list) { if (list == null) return null; return getCommaSeparatedListOfString(Arrays.asList(list)); }//ww w. j av a2s. c o m public static String getCommaSeparatedListOfString( Collection<String> list) { return getCommaSeparatedListOfString(list, "(", ")", true); } public static String getCommaSeparatedListOfString(String[] list, String open, String close, boolean singleQuoteElement) { List<String> listStr = null; if (list != null) { listStr = Arrays.asList(list); } return getCommaSeparatedListOfString(listStr, open, close, singleQuoteElement); } public static String getCommaSeparatedListOfString( Collection<String> list, String open, String close, boolean singleQuoteElement) { return getSeparatedListOfString(list, open, close, singleQuoteElement, ","); } public static String getSeparatedListOfString(Collection<String> list, String open, String close, boolean singleQuoteElement, String separator) { if (list == null) return null; StringBuffer buffer = new StringBuffer(open); for (Iterator<String> it = list.iterator(); it.hasNext();) { String item = it.next(); if (singleQuoteElement) { buffer.append("'" + item + "'"); } else { buffer.append(item); } if (it.hasNext()) { buffer.append(separator); } } buffer.append(close); return buffer.toString(); } }