Java / Java 21 Collection Framework features Interview questions
What is the SequencedSet interface?
SequencedSet<E> extends both Set<E> and SequencedCollection<E>, so it's a Set that also guarantees a defined encounter order and inherits the first/last/reversed methods.
It overrides reversed() with a covariant return type, so calling reversed() on a SequencedSet gives back another SequencedSet rather than a plain SequencedCollection.
LinkedHashSet and TreeSet (through NavigableSet) are the two standard implementations. A plain HashSet is deliberately excluded because its iteration order isn't guaranteed.
More Related questions...