Java / Java 21 Collection Framework features Interview questions
What is the difference between SequencedCollection and the Queue interface?
SequencedCollection and Queue both deal with ordered access, but they model different things: SequencedCollection is about having elements arranged with a defined first-to-last order and being able to reach either end, while Queue is specifically about FIFO-style processing semantics.
| SequencedCollection | Queue |
| Access to both first and last ends | Primarily designed around one end for insertion, another for removal |
| Has a reversed() view | No reversed() method of its own |
| Implemented by List and Deque | Implemented by LinkedList, PriorityQueue, ArrayDeque |
| Does not extend Queue | Does not extend SequencedCollection |
Notably, Queue itself does not extend SequencedCollection - PriorityQueue, for example, implements Queue but doesn't have a meaningful "first-to-last encounter order" in the iteration sense, since its iteration order isn't the same as its priority-based poll order, so it correctly stays outside the sequenced hierarchy.
More Related questions...