Use sequenced collections when encounter order and first/last operations should be explicit across Java lists, sets, and maps.
Sequenced collections give Java a standard vocabulary for ordered collections. Since JDK 21, the platform includes interfaces that express encounter order directly across several collection families.
This is a smaller feature than virtual threads, but it has a real design impact: code can describe first/last and reverse-order operations explicitly instead of relying on incidental knowledge about a particular implementation.
Java now has:
SequencedCollectionSequencedSetSequencedMapThese interfaces make ordered access more uniform across the standard library.
Before sequenced collections, Java had many ordered implementations but less uniform design vocabulary. Teams often knew that a particular type preserved order, but the API did not always make the intended operations obvious.
That created a subtle problem: the code depended on order, but the abstraction did not say so clearly enough.
Sequenced collections help because they make these expectations visible:
| Need | Older habit | Sequenced collection design |
|---|---|---|
| first and last item access | rely on List, Deque, or implementation-specific methods | express ordered access through a dedicated sequenced interface |
| reverse traversal | hand-written reverse logic or implementation knowledge | use the reverse view exposed by the API |
| ordered maps | rely on LinkedHashMap knowledge alone | model the API around an explicitly sequenced map |
1SequencedMap<String, Integer> counts = new LinkedHashMap<>();
2counts.put("low", 1);
3counts.put("medium", 3);
4counts.put("high", 8);
5
6Map.Entry<String, Integer> first = counts.firstEntry();
7Map.Entry<String, Integer> last = counts.lastEntry();
8
9for (var entry : counts.reversed().entrySet()) {
10 System.out.println(entry.getKey() + "=" + entry.getValue());
11}
The gain is not only convenience. The code now says that encounter order is part of the design.
Sequenced collections are useful when:
Typical fits include:
Sequenced collections do not erase the need to choose the right concrete type.
You still need to ask:
This feature improves abstraction quality. It does not remove collection choice.
Sequenced collections matter because they let Java APIs state order more honestly. That reduces accidental coupling to specific collection implementations and makes order-dependent code easier to review.