TreeMap in Java — a practical guide to Java TreeMap with clear examples you can reuse in real projects.
Java Tutorial Series (56/90). Prefer one article? Read the complete Java tutorial.
Short description
`TreeMap` keeps keys sorted and is useful for range-like ordered maps.
TreeMap
import java.util.TreeMap;
TreeMap<String, Integer> map = new TreeMap<>();
map.put("b", 2);
map.put("a", 1);
System.out.println(map.firstKey()); // a