Java Collection Sort sorted(Collection coll)

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

Description

sorted

License

Open Source License

Declaration

public static <T extends Comparable<? super T>> List<T> sorted(Collection<? extends T> coll) 

Method Source Code


//package com.java2s;
/*/*from   w  ww  .j  a va2 s . co  m*/
 *
 *  Managed Data Structures
 *  Copyright ? 2016 Hewlett Packard Enterprise Development Company LP.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  As an exception, the copyright holders of this Library grant you permission
 *  to (i) compile an Application with the Library, and (ii) distribute the 
 *  Application containing code generated by the Library and added to the 
 *  Application during this compilation process under terms of your choice, 
 *  provided you also meet the terms and conditions of the Application license.
 *
 */

import java.util.ArrayList;

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

import java.util.List;

public class Main {
    public static <T extends Comparable<? super T>> List<T> sorted(Collection<? extends T> coll) {
        if (coll == null || coll.isEmpty()) {
            return Collections.emptyList();
        }
        List<T> list = new ArrayList<>(coll);
        Collections.sort(list);
        return list;
    }

    public static <T> List<T> sorted(Collection<? extends T> coll, Comparator<? super T> cptr) {
        if (coll == null || coll.isEmpty()) {
            return Collections.emptyList();
        }
        List<T> list = new ArrayList<>(coll);
        Collections.sort(list, cptr);
        return list;
    }

    public static boolean isEmpty(Collection<?> coll) {
        return coll == null || coll.isEmpty();
    }
}

Related

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