... Sets
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 Comparator
. Class TreeSet
implements SortedSet
. The program in Fig. 16.16 places String
s into a TreeSet
. The String
s are sorted as they’re added to the TreeSet
. This example also demonstrates rangeview methods, which enable a program to view a portion of a collection.
Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.