JRishi JRishi - 8 months ago 17
Java Question

sorting object on insertion in hashmap

As per my knowledge of collection framework, if we need to sort object on insertion, we can use

and that object class should override
method of comparable class.

But, I want to know, IS there any way through which we can achieve same in
, is there any utility which will enable it to be sorted, while inserting object.

Thanks in advance.


No, HashMap is not a sorted map by design, it even does not implement SortedMap interface. See HashMap javadocs