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)
| 1863 | * elements cannot be compared to each other. |
| 1864 | */ |
| 1865 | @SuppressWarnings("unchecked") |
| 1866 | public static <T extends java.lang.Comparable<? super T>> void sort(List<T> list) { |
| 1867 | Object[] array = list.toArray(); |
| 1868 | Arrays.sort(array); |
| 1869 | int i = 0; |
| 1870 | ListIterator<T> it = list.listIterator(); |
| 1871 | while (it.hasNext()) { |
| 1872 | it.next(); |
| 1873 | it.set((T) array[i++]); |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | /** |
| 1878 | * Sorts the specified list using the specified comparator. The algorithm is |