Java / Java 21 Collection Framework features Interview questions
What is the difference between SequencedCollection and List?
SequencedCollection is a broader, more general interface that any collection with a defined encounter order can implement, while List is one specific, richer kind of ordered collection that happens to extend it.
| SequencedCollection | List |
| Defines only first/last access and reversal | Adds full index-based access - get(i), set(i, e), subList() |
| Implemented by List, Deque, and their subtypes | Implemented by ArrayList, LinkedList, Vector, etc. |
| Doesn't guarantee positional insertion at arbitrary indexes | Supports inserting/removing at any index |
In practice, every List is a SequencedCollection, but plenty of SequencedCollection implementations - like ArrayDeque - are not Lists, since they don't support arbitrary index access.
More Related questions...