Here you can find the source of sorted(Collection
Parameter | Description |
---|---|
collection | a parameter |
public static <E extends Comparable<E>> List<E> sorted(Collection<E> collection)
//package com.java2s; /******************************************************************************* * Copyright 2011 Danny Kunz/*w ww . j a v a2 s. c o m*/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Main { /** * Similar to {@link #sorted(Collection, Comparator)} using the {@link Comparable} interface of the given elements * * @param collection * @return new sorted {@link List} instance, null if given {@link Collection} is null */ public static <E extends Comparable<E>> List<E> sorted(Collection<E> collection) { // final Comparator<E> comparator = null; return sorted(collection, comparator); } /** * Returns a new {@link List} instance which is based on the elements of the given {@link Collection} and which is sorted using * the given {@link Comparator}<br> * If the given {@link Comparator} is null the natural order is used. <br> * The given {@link Collection} will kept unmodified, only the returned {@link List} will be sorted. * * @see Collections#sort(List, Comparator) * @param collection * @param comparator * @return a new {@link List} instance */ public static <E> List<E> sorted(Collection<E> collection, Comparator<E> comparator) { // final List<E> retlist = collection != null ? new ArrayList<E>(collection) : null; // if (retlist != null) { Collections.sort(retlist, comparator); } // return retlist; } }