Java / Java 21 Collection Framework features Interview questions
Describe the sequencedKeySet(), sequencedValues(), and sequencedEntrySet() methods?
These three methods on SequencedMap return ordered, sequenced views of the map's keys, values, and entries - counterparts to the plain keySet(), values(), and entrySet() from Map.
| Method | Returns |
sequencedKeySet() | A SequencedSet<K> of the keys, in encounter order |
sequencedValues() | A SequencedCollection<V> of the values, in encounter order |
sequencedEntrySet() | A SequencedSet<Entry<K,V>> of the entries, in encounter order |
Because the results are sequenced types, you can call getFirst(), getLast(), or reversed() directly on them, which the plain keySet()/values()/entrySet() views don't support.
More Related questions...