Here you can find the source of toString(Iterator> iterObjects)
public static String toString(Iterator<?> iterObjects)
//package com.java2s; import java.util.Iterator; public class Main { /**//from ww w . ja va 2 s . c o m * Generates a <code>String</code> value from the given <code>Iterator</code> of the form: * '[' object.toString() ',' object.toString() ',' ... ']' * * @param iterObjects the <code>Iterator</code> to dump into a <code>String</code> * @param allowEmptyLists if true, show empty lists as "[]" otherwise return null * @return the <code>String</code> representation of the <code>Iterator</code> or null if the <code>Iterator</code> is null * (or empty if allowEmptyLists is false) */ public static String toString(Iterator<?> iterObjects, boolean allowEmptyLists) { if (iterObjects == null || (!allowEmptyLists && !iterObjects.hasNext())) { return null; } else { StringBuilder stringBuilder = new StringBuilder("["); if (iterObjects.hasNext()) { stringBuilder.append(iterObjects.next().toString()); while (iterObjects.hasNext()) { stringBuilder.append(','); stringBuilder.append(iterObjects.next().toString()); } } stringBuilder.append(']'); return stringBuilder.toString(); } } public static String toString(short[] a) { StringBuilder stringBuilder = new StringBuilder("["); if (a != null && a.length > 0) { stringBuilder.append(a[0]); for (int i = 1; i < a.length; i++) { stringBuilder.append(','); stringBuilder.append(a[i]); } } stringBuilder.append(']'); return stringBuilder.toString(); } public static String toString(byte[] a) { StringBuilder stringBuilder = new StringBuilder("["); if (a != null && a.length > 0) { stringBuilder.append(a[0]); for (int i = 1; i < a.length; i++) { stringBuilder.append(','); stringBuilder.append(a[i]); } } stringBuilder.append(']'); return stringBuilder.toString(); } public static String toString(Iterator<?> iterObjects) { return toString(iterObjects, false); } }