Here you can find the source of sortedCollection(final Comparator super T> comparator, final Collection
private static <T> Iterable<T> sortedCollection(final Comparator<? super T> comparator, final Collection<T> input)
//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; } } }