Java Collection Sort sorted(Collection coll)

Here you can find the source of sorted(Collection coll)

Description

sorted

License

Open Source License

Parameter

Parameter Description
coll a parameter

Return

a new sorted List containing the elements of the given Collection.

Declaration

public static <E extends Comparable<E>> ArrayList<E> sorted(Collection<E> coll) 

Method Source Code

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

Related

  1. sort(Collection items)
  2. sortByDescendingOrder(Map collection)
  3. sortClassesByLevelOfInheritance(Collection> classes)
  4. sorted(Collection coll)
  5. sorted(Collection input)
  6. sorted(Collection collection)
  7. sorted(Collection ss)
  8. sorted(Collection c)
  9. sorted(Collection c)