The implementation of the method Collections.sort(List l, Comparator) should be implemented as follows: @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> void sort(List<T> list, Comparator<? super T> c) { list.sort(c); } and the default implementation in List.sort should be the previous implementation of Collectors.sort: default void sort(Comparator<? super E> c) { Object[] a = toArray(); Arrays.sort(a, (Comparator)c); ListIterator<E> i = listIterator(); for (Object e : a) { i.next(); i.set((E) e); } } Thus ensuring that Collection.sort will use the most optimal sort implementation provided by the list implementation.
|