TreeMap in Java is one of the implementation of the Map interface. How it differs from the other implementation HashMap is that unlike HashMap which is unordered, TreeMap is Sorted . TreeMap is sorted according to the natural ordering of its keys by default. If you want different sort ordering then you will have to provide a Comparator at the TreeMap construction time. Java TreeMap is a Red-Black tree based implementation of Map. TreeMap class extends AbstractMap and implements NavigableMap , Cloneable and Serializable interfaces. Features of TreeMap Some of the features of the TreeMap in Java which are discussed in this post are as follows- In TreeMap elements are sorted by keys. In TreeMap values may be duplicate but a key has to be unique. TreeMap doesn’t permit null keys, null values are permitted though. TreeMap in Java is not thread safe. The iterators returned by all of TreeMap’s "collection view methods" are fail-fast. Which means,
Java, Spring, Web development tutorials with examples