java.util · java.base · since Java 21
SequencedCollection
public interface SequencedCollection<E> extends Collection<E>Java 21 unification of collections with a well-defined encounter order: first/last access and a reversed view, inherited by List, Deque, and SortedSet.
- Retrofitted onto List, Deque, LinkedHashSet, and SortedSet in Java 21 — one consistent end-access API.
Key methods
void addFirst(E) / addLast(E) | Insert at the front / back (may be unsupported on immutable views). |
E getFirst() / getLast() | Peek the ends (throws NoSuchElementException if empty). |
E removeFirst() / removeLast() | Remove and return an end element. |
SequencedCollection<E> reversed() | A reverse-order VIEW — writes flow through. |