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

前端 未结 6 618
醉酒成梦
醉酒成梦 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:26

    My Map contains keys sorted in alphabetical order

    This is not true.

    Use http://download.oracle.com/javase/6/docs/api/java/util/SortedMap.html or sort your keys before iterate

提交回复
热议问题