Bifalgorithm post · Computer science one · Dynamic Data Structures
How do Java sets store unordered unique elements?
How do Java sets store unordered unique elements? (Computer science one · Dynamic Data Structures) — "Another type of collection supported by the Collections l…
Ideas in this flowchart
- A Set is a collection supported by the Collections library.
- Properties of a Set
- A Set is unordered, unlike a List.
- There is no concept of a first or last element.
- A Set does not allow duplicate elements.
- HashSet is a commonly used implementation of the Set interface.
- The example creates a Set<String> named names using HashSet<String>.
- The set receives Robin, Little John, and Marian; adding Robin again has no effect.
- An index-based get() method cannot be used with a Set.
- An enhanced for loop can iterate over the elements.
- The three names may be printed in any order, and repeated executions may produce different enumerations.
- Duplicate detection depends on the equals() and possibly hashCode() implementations of the objects.