18.2 Sets
A set is an (initially) unordered collection of elements. Each element may occur only once. For sets, the Java library provides the interface java.util.Set . Popular implementing classes include the following:
-
HashSet: For fast set implementation by hashing method (based on HashMap ).
-
TreeSet : Sets are implemented by balanced binary trees that allow sorting.
-
LinkedHashSet : Fast set implementation while maintaining insertion order.
-
EnumSet : A special set exclusively for enumerations.
-
CopyOnWriteArraySet : For fast, thread-safe data structures, optimized for many read operations but few write operations.
18.2.1 A First Example of a Set
Our next example program analyzes a text and recognizes cities that were ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access