Sorts the specified list in ascending natural order. The algorithm is stable which means equal elements don't get reordered. @param list the list to be sorted. @throws ClassCastException when an element in the List does not implement Comparable or elements cannot
(List<T> list)
| 1936 | * elements cannot be compared to each other. |
| 1937 | */ |
| 1938 | @SuppressWarnings("unchecked") |
| 1939 | public static <T extends Comparable<? super T>> void sort(List<T> list) { |
| 1940 | Object[] array = list.toArray(); |
| 1941 | Arrays.sort(array); |
| 1942 | int i = 0; |
| 1943 | ListIterator<T> it = list.listIterator(); |
| 1944 | while (it.hasNext()) { |
| 1945 | it.next(); |
| 1946 | it.set((T) array[i++]); |
| 1947 | } |
| 1948 | } |
| 1949 | |
| 1950 | /** |
| 1951 | * Sorts the specified list using the specified comparator. The algorithm is |