sort a Collection by Comparator - Java java.util

Java examples for java.util:Collection Compare

Description

sort a Collection by Comparator

Demo Code


//package com.java2s;
import java.util.*;

public class Main {
    public static <T> List<T> sort(final Collection<T> collection,
            final Comparator<T> comparator) {
        final List<T> sorted = new ArrayList<T>(collection);
        if (sorted.size() > 1) {
            Collections.sort(sorted, comparator);
        }/*w w  w . j  av a 2s .c om*/
        return sorted;
    }
}

Related Tutorials