Sorts the specified list into ascending order, according to the
natural ordering of its elements.
All elements in the list must implement the Comparable
interface. Furthermore, all elements in the list must be
mutually comparable (that is, e1.compareTo(e2)
must not throw a ClassCastException
for any elements
e1
and e2
in the list).
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
The specified list must be modifiable, but need not be resizable.
<T> | the class of the objects in the list | |
list | the list to be sorted. |
ClassCastException | if the list contains elements that are not mutually comparable (for example, strings and integers). | |
UnsupportedOperationException | if the specified list's
list-iterator does not support the set operation. | |
IllegalArgumentException | (optional) if the implementation
detects that the natural ordering of the list elements is
found to violate the Comparable contract |
List.sort(Comparator)
@implNote
This implementation defers to the List.sort(Comparator)
method using the specified list and a null
comparator.
Diagram: Collections