LinkedHashMap now exposes firstEntry, lastEntry and reversed views.
LinkedHashMap<String, Integer> m = new LinkedHashMap<>();
m.put("a", 1); m.put("b", 2); m.put("c", 3);
System.out.println(m.firstEntry());
System.out.println(m.lastEntry());
a=1
c=3
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-07-26