Java Collection Sort sort(Collection items)

Here you can find the source of sort(Collection items)

Description

Sort the collection and return as list.

License

Open Source License

Parameter

Parameter Description
items a parameter

Declaration

public static <T extends Comparable<? super T>> List<T> sort(Collection<T> items) 

Method Source Code


//package com.java2s;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;

import java.util.LinkedList;
import java.util.List;

public class Main {
    /**/*from  w w w. j av a  2  s . co  m*/
     * Sort the collection and return as list.
     * 
     * @param items
     * @return
     */
    public static <T extends Comparable<? super T>> List<T> sort(Collection<T> items) {
        List<T> list = toList(items);
        Collections.sort(list);

        return list;
    }

    /**
     * Sort the collection and return as list.
     * 
     * @param items
     * @return
     */
    public static <T> List<T> sort(Collection<T> items, Comparator<? super T> c) {
        List<T> list = toList(items);
        Collections.sort(list, c);

        return list;
    }

    /**
     * Convert the collection to linked list.
     * 
     * @param items
     * @return
     */
    public static <T> List<T> toList(Collection<T> items) {
        return new LinkedList<T>(items);
    }
}

Related

  1. getSorted(Collection collection)
  2. isSort(Collection c)
  3. sort(Collection collection)
  4. sort(Collection collection, Comparator comparator)
  5. sortByDescendingOrder(Map collection)
  6. sortClassesByLevelOfInheritance(Collection> classes)
  7. sorted(Collection coll)
  8. sorted(Collection input)