The collections framework also includes the
SortedSet interface (which extends
Set) for sets that maintain their elements in sorted order—either the elements’ natural order (e.g., numbers are in ascending order) or an order specified by a
SortedSet. The program in Fig. 16.16 places
Strings into a
Strings are sorted as they’re added to the
TreeSet. This example also demonstrates range-view methods, which enable a program to view a portion of a collection.