Java Utililty Methods Collection Sort

List of utility methods to do Collection Sort

Description

The list of methods to do Collection Sort are organized into topic(s).

Method

ListgetSorted(Collection collection)
Return a sorted list with the collection's elements.
List<T> ret = new ArrayList<T>(collection.size());
ret.addAll(collection);
Collections.sort(ret);
return ret;
booleanisSort(Collection c)
is Sort
E pointer = null, next;
Iterator<E> it = c.iterator();
if (it.hasNext())
    pointer = it.next();
while (it.hasNext()) {
    next = it.next();
    if (pointer.compareTo(next) > 0)
        return false;
...
voidsort(Collection collection)
sort
if (isNotEmpty(collection)) {
    Object[] objs = collectionToArray(collection);
    Arrays.sort(objs);
    collection.clear();
    collection.addAll(arrayToCollection(objs));
Listsort(Collection collection, Comparator comparator)
sort
List<T> list = new ArrayList<T>(collection);
Collections.sort(list, comparator);
return list;
Listsort(Collection items)
Sort the collection and return as list.
List<T> list = toList(items);
Collections.sort(list);
return list;
List>sortByDescendingOrder(Map collection)
sort By Descending Order
List<Map.Entry<T, Double>> list = new ArrayList<Map.Entry<T, Double>>(collection.entrySet());
Collections.sort(list, new Comparator<Map.Entry<T, Double>>() {
    public int compare(Map.Entry<T, Double> o1, Map.Entry<T, Double> o2) {
        if (o1.getValue() > o2.getValue()) {
            return -1;
        } else if (o1.getValue() < o2.getValue()) {
            return 1;
        } else {
...
List>sortClassesByLevelOfInheritance(Collection> classes)
sort Classes By Level Of Inheritance
List<Class<?>> result = new ArrayList<Class<?>>(classes);
Collections.sort(result, new Comparator<Class<?>>() {
    public int compare(Class<?> c1, Class<?> c2) {
        int l1 = getLevelOfInheritance(c1);
        int l2 = getLevelOfInheritance(c2);
        if (l1 < l2) {
            return -1;
        } else if (l1 > l2) {
...
Listsorted(Collection coll)
sorted
if (coll == null || coll.isEmpty()) {
    return Collections.emptyList();
List<T> list = new ArrayList<>(coll);
Collections.sort(list);
return list;
Listsorted(Collection input)
sorted
List<T> sortable = new ArrayList<>(input);
Collections.sort(sortable);
return sortable;
ArrayListsorted(Collection coll)
sorted
final ArrayList<E> result = new ArrayList<E>(coll);
Collections.sort(result);
assert result != null;
assert result != coll;
return result;