Here you can find the source of printCollectionSorted(Collection l, String indent)
@SuppressWarnings("unchecked") public static String printCollectionSorted(Collection l, String indent)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class Main { @SuppressWarnings("unchecked") public static String printCollectionSorted(Collection l, String indent) { List sortedCollection = new ArrayList(l); Collections.sort(sortedCollection); return printCollection(sortedCollection, indent); }//from w w w . j a va 2 s. com public static String printCollection(Collection l) { return printCollection(l, ""); } public static String printCollection(Collection l, String indent) { if (l == null) { return indent + "(null)"; } if (l.isEmpty()) { return indent + "(empty collection)"; } StringBuilder result = new StringBuilder(); for (Object o : l) { result.append(indent).append(o).append("\n"); } result.deleteCharAt(result.length() - 1); return result.toString(); } }