TreeMap
Learn TreeMap (Map Interface, Collection Framework) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
What is a TreeMap? A TreeMap is a map whose keys are always kept sorted . Put the pairs in any order and they come out ordered by key: forts A to Z, numbers small to large. On top of the ordinary map methods it can answer neighbour and range questions : "which key comes just after 500?" or "give me all entries between P and S". Package java.util . Implements NavigableMap (which extends SortedMap , which extends Map ). Sorted by key : by the keys' natural order ( Comparable ) or by a Comparator you supply. Unique keys : two keys are "the same" when compareTo / compare returns 0 (not when equals...