Here you can find the source of sort(List
Parameter | Description |
---|---|
T | type. |
list | the list to sort. |
comparator | the comparator to use when sorting. |
public static <T> List<T> sort(List<T> list, Comparator<? super T> comparator)
//package com.java2s; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Main { /**/* ww w. ja v a 2s.c o m*/ * Creates a copy of and sorts the given list. * * @param <T> type. * @param list the list to sort. * @param comparator the comparator to use when sorting. * @return a sorted list. */ public static <T> List<T> sort(List<T> list, Comparator<? super T> comparator) { List<T> copy = new ArrayList<>(list); Collections.sort(copy, comparator); return copy; } }