Java Collection Sort getSorted(Collection collection)

Here you can find the source of getSorted(Collection collection)

Description

Return a sorted list with the collection's elements.

License

Open Source License

Parameter

Parameter Description
collection a parameter

Declaration

public static <T extends Comparable<T>> List<T> getSorted(Collection<T> collection) 

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 {
    /**/*from w  ww  . ja  va 2  s .  co m*/
     * Return a sorted list with the collection's elements.
     * 
     * @param collection
     * @return
     */
    public static <T extends Comparable<T>> List<T> getSorted(Collection<T> collection) {
        List<T> ret = new ArrayList<T>(collection.size());
        ret.addAll(collection);
        Collections.sort(ret);
        return ret;
    }
}

Related

  1. isSort(Collection c)
  2. sort(Collection collection)
  3. sort(Collection collection, Comparator comparator)
  4. sort(Collection items)