Java Collection Sort sortedCollection(final Comparator comparator, final Collection input)

Here you can find the source of sortedCollection(final Comparator comparator, final Collection input)

Description

sorted Collection

License

Open Source License

Declaration

private static <T> Iterable<T> sortedCollection(final Comparator<? super T> comparator,
            final Collection<T> input) 

Method Source Code

//package com.java2s;
/*/*from  w w w.ja v a2s.  com*/
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

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

import java.util.List;

public class Main {
    private static <T> Iterable<T> sortedCollection(final Comparator<? super T> comparator,
            final Collection<T> input) {
        if (input.size() > 1) {
            final List<T> ret = new ArrayList<>(input);
            Collections.sort(ret, comparator);
            return ret;
        } else {
            return input;
        }
    }
}

Related

  1. sorted(Collection ss)
  2. sorted(Collection c)
  3. sorted(Collection c)
  4. sorted(Collection collection)
  5. sortedByName(Collection unsorted, Comparator comparator, T... exclusions)
  6. sortedIfPossible(Collection collection)
  7. sortEntities(Collection entities, Comparator comparator)
  8. sortMapByValues( final Map> related_region_counts, Comparator>> comparator)
  9. toSortedStrings(final Collection objects)