TreeMap in Java is a SortedMap and it maintains Sorting order when you insert object on it.
You can specify Sorting order while Creating TreeMap by providing an explicit Comparator to
TreeMap. Basically you can create TreeMap in Java by different ways, a TreeMap with natural sorting order, and TreeMap with custom Sorting Order by providing Comparator, Copying Sorting order from other SortedMap etc. TreeMap has specific constructor for these conditions. We will see these in section of creating instance of TreeMap in Java. We will also see how to put element, get element, iterate over TreeMap, clearing and reusing TreeMap in this Java TreeMap tutorial. This article is in continuation of my collection series e.g. HashMap vs HashSet , SynchronziedHashMap vs ConcurrentHashMap and Iterator vs Enumeration in Java