Here you can find the source of print(Collection
public static <T> String print(Collection<T> objs)
//package com.java2s; //License from project: LGPL import java.io.*; import java.net.*; import java.util.*; public class Main { public static String print(Throwable t) { return printStackTrace(t); }//from w w w . j a va 2 s . c o m public static <T> String print(Collection<T> objs) { StringBuilder sb = new StringBuilder(); boolean first = true; for (T obj : objs) { if (first) first = false; else sb.append(", "); sb.append(obj); } return sb.toString(); } public static <T> String print(Map<T, T> map) { StringBuilder sb = new StringBuilder(); boolean first = true; for (Map.Entry<T, T> entry : map.entrySet()) { if (first) first = false; else sb.append(", "); sb.append(entry.getKey()).append("=").append(entry.getValue()); } return sb.toString(); } public static String print(List<NetworkInterface> interfaces) { StringBuilder sb = new StringBuilder(); boolean first = true; for (NetworkInterface intf : interfaces) { if (first) { first = false; } else { sb.append(", "); } sb.append(intf.getName()); } return sb.toString(); } /** * Use with caution: lots of overhead */ public static String printStackTrace(Throwable t) { StringWriter s = new StringWriter(); PrintWriter p = new PrintWriter(s); t.printStackTrace(p); return s.toString(); } }