February 2014
Beginner
1248 pages
62h 25m
English
Method sort sorts the elements of a List, which must implement the Comparable interface. The order is determined by the natural order of the elements’ type as implemented by a compareTo method. For example, the natural order for numeric values is ascending order, and the natural order for Strings is based on their lexicographical ordering (Section 14.3). Method compareTo is declared in interface Comparable and is sometimes called the natural comparison method. The sort call may specify as a second argument a Comparator object that determines an alternative ordering of the elements.
Figure 16.6 uses Collections method sort to order the elements of a List in ascending order (line 17). Method sort ...
Read now
Unlock full access