Last Updated: June 6, 2026
TreeMap is the Map implementation that keeps its entries sorted by key at all times. Unlike HashMap (no order) or LinkedHashMap (insertion order), TreeMap stores entries in a self-balancing binary search tree, so iterating its entries always walks them in key order, and a family of navigation methods like floorKey, ceilingKey, headMap, and subMap are available. This lesson covers how TreeMap is structured, how its key-based operations perform, the navigation methods that make it useful for range queries, and a few rough edges (like null keys) to watch for.