TreeMap is a sorted map implementation based on a red-black tree. The elements are sorted by their keys, which are inserted into the map using the put() method or can be specified in the constructor. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used. So what is red-black tree? A red-black tree..