HashMap is already sorted by key?

后端 未结 3 2013
慢半拍i
慢半拍i 2021-01-20 23:39

I thought that HashMap is unordered, and when iterating over the keys, you can\'t know what will be the order? In this example, it looks like the map is already sorted by the ke

3条回答
  •  有刺的猬
    2021-01-21 00:27

    Treemap is a sorted map which contains keys in sorted order and HashMap can't gurantee you sorted map.So,always choose Treemap when ever you want sorted keys

提交回复
热议问题