How to sort Map values by key in Java?

后端 未结 15 2462
野性不改
野性不改 2020-11-22 08:26

I have a Map that has strings for both keys and values.

Data is like following:

\"question1\", \"1\"
\"question9\", \"1\"
\"que

15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 09:18

    Just use TreeMap

    new TreeMap(unsortMap);
    

    Be aware that the TreeMap is sorted according to the natural ordering of its 'keys'

提交回复
热议问题