Java tutorial
//package com.java2s; /* * Copyright (c) 2008-2010, Intel Corporation. * Copyright (c) 2006-2007, The Trustees of Stanford University. * All rights reserved. * Licensed under the terms of the New BSD License. */ import java.util.Collection; import java.util.Iterator; public class Main { public static <T> String toString(Collection<T> c, String prefix, String sep, String suffix) { if (c == null || c.size() == 0) return prefix + suffix; Iterator<T> it = c.iterator(); String result = prefix + it.next(); while (it.hasNext()) result += sep + it.next(); return result + suffix; } public static <T> String toString(final Collection<T> a) { return toString(a, "", ",", ""); } }