Java / Java 21 Collection Framework features Interview questions
What is the difference between removeFirst()/removeLast() on SequencedCollection and on Deque?
Structurally, they're the same method signatures - Deque already had removeFirst() and removeLast() long before Java 21, and JEP 431 simply promoted them to the new, more general SequencedCollection interface.
The practical difference is scope: on Deque, these methods were only ever guaranteed to exist on deque-shaped collections like ArrayDeque. Now, because SequencedCollection sits above both List and Deque in the hierarchy, the same two methods are also available on ArrayList and LinkedList when accessed through a List reference.
List<String> list = new ArrayList<>(List.of("a", "b", "c")); list.removeFirst(); // now legal on List too, not just Deque
So the behavior is unchanged; what's different after Java 21 is that code written generically against SequencedCollection can call removeFirst()/removeLast() without caring whether the concrete type is a list or a deque.
More Related questions...