Here you can find the source of collectionToString(Collection> coll, String connectSymbol)
public static String collectionToString(Collection<?> coll, String connectSymbol)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { public static String collectionToString(Collection<?> coll, String connectSymbol) { return collectionToString(coll, connectSymbol, "", ""); }/*from w w w .ja v a 2 s . co m*/ public static String collectionToString(Collection<?> coll, String connectSymbol, String leading, String trailing) { return arrayToString(coll.toArray(), connectSymbol, leading, trailing); } public static <T> String arrayToString(T[] array) { return arrayToString(array, ",", "", ""); } public static <T> String arrayToString(T[] array, String connectSymbol) { return arrayToString(array, connectSymbol, "", ""); } public static <T> String arrayToString(T[] array, String leading, String trailing) { return arrayToString(array, ",", leading, trailing); } public static <T> String arrayToString(T[] array, String connectSymbol, String leading, String trailing) { connectSymbol = (connectSymbol == null ? "" : connectSymbol); leading = (leading == null ? "" : leading); trailing = (trailing == null ? "" : trailing); int len = array.length; if (len == 0) return ""; StringBuffer buf = new StringBuffer(len * 12 + leading.length() + trailing.length()); for (int i = 0; i < len - 1; i++) { buf.append(leading).append(array[i].toString()).append(trailing).append(connectSymbol); } return buf.append(leading).append(array[len - 1].toString()).append(trailing).toString(); } }