Here you can find the source of print(java.util.Collection collection)
String
representing the elements of collection
in a human readable format.
String
representing collection
.
public static final String print(java.util.Collection collection)
//package com.java2s; // Licensed under the terms of the GNU GPL; see COPYING for details. public class Main { /** Return a <code>String</code> representing the elements of <code>collection</code> in a human readable format. <BR> <B>effects:</B> Iterates over <code>collection</code>, calling <code>toString()</code> on each element and appending the result to a <code>String</code>. The format of the returned <code>String</code> is <NOBR>{ elem1, elem2, ... , elemN }</NOBR> @return A <code>String</code> representing <code>collection</code>. *///from w w w. ja v a2 s. c o m public static final String print(java.util.Collection collection) { StringBuffer sb = new StringBuffer("{ "); java.util.Iterator iter = collection.iterator(); while (iter.hasNext()) { Object elem = iter.next(); sb.append(elem.toString()); if (iter.hasNext()) { sb.append(", "); } } sb.append(" }"); return sb.toString(); } }