Professional Documents
Culture Documents
TreeMap in Java
TreeMap in Java
studentMap ->
{1,"Abhishek",10:"Gaurav",15:"Rohan"}
When used with an empty TreeMap() constructor
the keys are sorted in the natural sorting order,
which is ascending for integer and string keys.
studentMap ->
{Student(15),"Dancing",Student(10):"Singing",Student(1):
"Painting"}
In Example-2 we passed a comparator (which
sorts in descending order) to the TreeMap
constructor and it sorted the map according to
the Student's roll no in descending order.