Here you can find the source of sorted(Collection
Parameter | Description |
---|---|
coll | a parameter |
public static <E extends Comparable<E>> ArrayList<E> sorted(Collection<E> coll)
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; public class Main { /**/* www.jav a2s. c o m*/ * @param coll * @return a new sorted List containing the elements of the given Collection. * @precondition coll != null * @postcondition result != null * @postcondition result != coll */ public static <E extends Comparable<E>> ArrayList<E> sorted(Collection<E> coll) { final ArrayList<E> result = new ArrayList<E>(coll); Collections.sort(result); assert result != null; assert result != coll; return result; } /** * @param coll * @param comparator Determines the ordering. If <code>null</code>, the natural ordering of the elements is used. * @return a new sorted List containing the elements of the given Collection. * @precondition coll != null * @postcondition result != null * @postcondition result != coll */ public static <E> ArrayList<E> sorted(Collection<E> coll, Comparator<? super E> comparator) { final ArrayList<E> result = new ArrayList<E>(coll); Collections.sort(result, comparator); assert result != null; assert result != coll; return result; } }