NOTE

TreeMap

Sorted and navigable maps, key ordering, logarithmic operations, and comparator consistency.

JavaCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

TreeMap is a sorted NavigableMap, commonly implemented as a balanced search tree. Lookup, insertion, and removal are logarithmic in map size.

Keys are ordered either by natural ordering or a supplied Comparator. The ordering should be consistent with the map’s intended equality semantics; a comparator that returns zero for distinct logical keys makes them occupy the same ordering position.

Use TreeMap when range queries, floor/ceiling operations, or sorted iteration are required—not as a faster HashMap replacement.

Loading helpful count