Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static String singleDump(final Collection<?> l) { final StringBuilder sb = new StringBuilder(); if (l == null) { sb.append("[]"); } else if (l.isEmpty()) { sb.append("[]"); } else { final Iterator<?> iterator = l.iterator(); int cnt = 0; sb.append("["); while (iterator.hasNext()) { if (cnt++ > 0) { sb.append(", "); } sb.append(iterator.next().toString()); } sb.append("]"); } return (sb.toString()); } /** * Single dump. * * @param l the l * @return the string */ public static String singleDump(final Object[] l) { final StringBuilder sb = new StringBuilder(); if (l == null) { sb.append("[]"); } else if (l.length == 0) { sb.append("[]"); } else { int cnt = 0; sb.append("["); for (final Object o : l) { if (cnt++ > 0) { sb.append(", "); } sb.append(o.toString()); } sb.append("]"); } return (sb.toString()); } }