How to iterate a HashMap using the natural entrySet() order?

前端 未结 6 581
醉酒成梦
醉酒成梦 2021-01-02 13:12

My Map contains keys sorted in alphabetical order. When I display it, I\'m using entrySet().iterator(), but my results are not in the alphabetical order. How can I get my re

6条回答
  •  一整个雨季
    2021-01-02 13:18

    Use TreeMap:

    A Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used...

提交回复
热议问题