Java / Java 21 Collection Framework features Interview questions
What is the Sequenced Collections feature introduced in Java 21?
Sequenced Collections, delivered through JEP 431, is a set of new interfaces added in Java 21 that give collections with a defined encounter order a common way to access their first and last elements and to view them in reverse.
Before Java 21, List had get(0) and index-based tricks, Deque had its own first/last methods, and LinkedHashMap/LinkedHashSet had no first-class way to grab the first or last entry - each type solved the same problem differently or not at all.
JEP 431 unifies this by introducing three new interfaces - SequencedCollection, SequencedSet, and SequencedMap - and retrofitting existing classes like ArrayList, LinkedHashSet, LinkedHashMap, and TreeMap to implement them, all without breaking any existing code.
More Related questions...