The General sort algorithm is a sort of array, and it uses random access methods. However, access to the list is inefficient. In fact, you can use merge sort to sort the list efficiently. The implementation of Java then is to simply transfer all the elements into an array, sort the arrays, and then copy the sorted sequence back to the list.
1 /**2 * Sorts the specified list according to the order induced by the3 * Specified comparator. All elements in the list must be <i>mutually4 * comparable</i> using the specified comparator (that's,5 * {@codeC.compare (E1, E2)} must not throw a {@codeClassCastException}6 * For any elements {@codeE1} and {@codeE2} in the list).7 *8 * <p>this sort is guaranteed to be <i>stable</i>: Equal elements 'll9 * Not being reordered as a result of the sort.Ten * One * <p>the specified list must is modifiable, but need isn't be resizable. A * - * @implNote - * This implementation defers to the {@linkList#sort (Comparator)} the * method using the specified list and comparator. - * - * @param<T> The class of the objects in the list - * @paramlist the list to is sorted. + * @paramc The comparator to determine the order of the list. A - * {@codeNULL} value indicates that the elements ' <i>natural + * ordering</i> should be used. A * @throwsclasscastexception If the list contains elements that is not at * <i>mutually comparable</i> using the specified comparator. - * @throwsunsupportedoperationexception If the specified list ' s - * List-iterator does not support the {@codeset} operation. - * @throwsillegalargumentexception (optional) If the comparator is - * found to violate the {@linkComparator} contract - * @seeList#sort (Comparator) in */ -@SuppressWarnings ({"Unchecked", "Rawtypes"}) to Public Static<T>voidSort (list<t> List, comparator<?SuperT>c) { + List.sort (c); -}
View Code
Look at the Java built-in sort () function from the source code