CKTIS / Java
util.SequencedMap: practical reference
util.SequencedMap: practical reference: SequencedMap<K,V> is a map with a defined encounter order for mappings, operations on its first and last entries, and a reverse-ordered view.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
java.util.SequencedMapSequencedMap<K,V> is a map with a defined encounter order for mappings, operations on its first and last entries, and a reverse-ordered view.
Use it for ordered maps that must inspect, remove, or reposition end mappings while preserving encounter order in forEach.
putFirst, putLast, and polling are optional, so an implementation may throw UnsupportedOperationException; do not assume its views are mutable.
firstEntry and lastEntry return null when empty and an unmodifiable copy otherwise; reversed is a view rather than an independent map.
The example exercises the documented element in a small deterministic program and compares exact standard output.
Examples
public class Main {
public static void main(String[] args) throws Exception {
java.util.SequencedMap<String, Integer> map = new java.util.LinkedHashMap<>();
map.put("a", 1);
map.put("b", 2);
System.out.println(map.firstEntry());
System.out.println(map.lastEntry());
}
}
Result
a=1 b=2
The example exercises the documented element in a small deterministic program and compares exact standard output.