Here you can find the source of toString(Collection
public static <T> String toString(Collection<T> a, String begStr, String sepStr, String endStr)
//package com.java2s; /*//from w w w .ja v a2s . co m * Copyright (c) 2006-07, The Trustees of Stanford University. All * rights reserved. * Licensed under the terms of the GNU GPL; see COPYING for details. */ import java.util.Collection; import java.util.Iterator; public class Main { public static <T> String toString(Collection<T> a, String begStr, String sepStr, String endStr) { int n = a.size(); if (n == 0) return begStr + endStr; Iterator<T> it = a.iterator(); String s = begStr + it.next(); while (it.hasNext()) s += sepStr + it.next(); return s + endStr; } public static <T> String toString(Collection<T> a) { return toString(a, "", ",", ""); } }