1.

What Is Treemap In Java?

Answer»

TreeMap is also one of the implementation of the Map interface LIKE HashMap and LinkedHashMap. TreeMap class implements the NavigableMap interface and extends the AbstractMap class.

How it differs from other implementations of the Map interface is that objects in TreeMap are stored in sorted order. The elements are ORDERED using their natural ORDERING or a comparator can be provided at map creation time to PROVIDE custom ordering.

One important point about TreeMap is, though HashMap and LinkedHashMap allow one null as key, TreeMap doesn't allow null as key. Any attempt to ADD null in a TreeMap will result in a NullPointerException.

TreeMap is also one of the implementation of the Map interface like HashMap and LinkedHashMap. TreeMap class implements the NavigableMap interface and extends the AbstractMap class.

How it differs from other implementations of the Map interface is that objects in TreeMap are stored in sorted order. The elements are ordered using their natural ordering or a comparator can be provided at map creation time to provide custom ordering.

One important point about TreeMap is, though HashMap and LinkedHashMap allow one null as key, TreeMap doesn't allow null as key. Any attempt to add null in a TreeMap will result in a NullPointerException.



Discussion

No Comment Found