Java / Java 21 Collection Framework features Interview questions
List the collection classes that implement SequencedSet in Java 21?
| Class | How it qualifies |
LinkedHashSet | Implements SequencedSet directly - insertion order is its encounter order |
TreeSet | Implements SequencedSet indirectly, through NavigableSet |
No other standard Set implementation qualifies. HashSet and its subclasses are left out because their iteration order isn't defined by contract, so promising a "first" or "last" element wouldn't be meaningful.
Custom Set implementations can also opt in by implementing SequencedSet themselves, as long as they can genuinely guarantee an encounter order.
More Related questions...