Java / Java 21 Collection Framework features Interview questions
What is the SequencedMap interface?
SequencedMap<K,V> extends Map<K,V> and adds methods for working with the first and last entries of a map that has a defined encounter order, plus a reversed() view of the whole map.
Its new methods include firstEntry(), lastEntry(), pollFirstEntry(), pollLastEntry(), putFirst(K,V), putLast(K,V), reversed(), and three view methods: sequencedKeySet(), sequencedValues(), and sequencedEntrySet().
LinkedHashMap implements it directly, and TreeMap implements it through NavigableMap. A plain HashMap does not implement it, since hash-based maps have no guaranteed order.
More Related questions...