Java Collection Print printCollectionSorted(Collection l, String indent)

Here you can find the source of printCollectionSorted(Collection l, String indent)

Description

print Collection Sorted

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static String printCollectionSorted(Collection l, String indent) 

Method Source Code


//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();
    }
}

Related

  1. printCollection(Collection col)
  2. printCollection(Collection collections)
  3. printCollection(final Collection collection)
  4. printCollection(String name, Collection collection)
  5. printCollectionDebug(Collection c)
  6. printElement(Collection pCollection, boolean pAllElement)
  7. printElementsUnderCollection(Collection collection)
  8. printList(Collection collection)
  9. println(Collection lines, String suffix, String prefix)