码上敲享录 > java入门知识分享 > Map的值排序(java)

Map的值排序(java)

上一章章节目录下一章 2019-03-18已有1484人阅读 评论(0)

Map的键排序(java)


解决方法:

Map<String,Integer> idsMap=new HashMap<String,Integer>();

List<Map.Entry<String,Integer>> list2 = new ArrayList<Map.Entry<String,Integer>>(idsMap.entrySet());


       Collections.sort(list2,new Comparator<Map.Entry<String,Integer>>() {

           public int compare(Entry<String, Integer> o1,

                   Entry<String, Integer> o2) {

                // 降序

                return o2.getValue().compareTo(o1.getValue());

                // 升序

                //return o2.getValue().compareTo(o1.getValue());

           }

           

       });


对map的键key进行排序请参考:http://www.yayihouse.com/yayishuwu/chapter/1816


向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交