Java Data StructuresLesson 66Free preview
Java HashSet
This lesson is part of Java · All levels
Summary
HashSet is the most popular set implementation that stores unique elements using hashing mechanisms on the internal HashMap. The add, remove, and contain operations run on average, making them very fast for big data. But remember, the order of the elements when iterated is unreliable.
Key points
- No order guarantees; iterations can change when the contents of the set change
- Uniqueness depends heavily on the correct spelling of hashCode() and equals()
- 16 built-in capacity with load factor 0.75 as the magnification threshold
- Allowing exactly one element
- Elements whose hash changes after entering the set can appear to be missing from the set
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.