Here you can find the source of collectionToString(Collection
public static <T> String collectionToString(Collection<T> list)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static <T> String collectionToString(Collection<T> list, String splitter) {//from w w w. j av a 2 s . co m if (list.size() == 0) return ""; Iterator iterator = list.iterator(); String value = iterator.next().toString(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(value); while (iterator.hasNext()) { value = iterator.next().toString(); stringBuilder.append(splitter); stringBuilder.append(value); } return stringBuilder.toString(); } public static <T> String collectionToString(Collection<T> list) { return collectionToString(list, ", "); } }