JRishi JRishi - 1 year ago 54
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download