Java / Java 21 Collection Framework features Interview questions
What are the new methods added by the SequencedCollection interface?
SequencedCollection adds seven methods on top of what Collection already provides, giving every implementing type a consistent way to work with its ends.
| Method | Purpose |
addFirst(E) | Insert an element at the start |
addLast(E) | Insert an element at the end |
getFirst() | Read the first element |
getLast() | Read the last element |
removeFirst() | Remove and return the first element |
removeLast() | Remove and return the last element |
reversed() | Return a reverse-ordered view |
Not every implementation supports every method - an immutable list, for instance, implements the interface but throws UnsupportedOperationException from the mutating ones.
More Related questions...