java HashMap--统计其中有相同value的key的个数


//统计每个等级的人数
        //<pid,topLevel>
        Map<String,Integer> map=new HashMap<>();
        map.put("1001",3);
        map.put("1002",4);
        map.put("1003",3);
 
        Map<Integer,Integer> res=new HashMap<>();
        for (Map.Entry<String,Integer> entry:map.entrySet()){
            if (res.containsKey(entry.getValue())){
                res.put(entry.getValue(),res.get(entry.getValue())+1);
            }else{
                res.put(entry.getValue(),1);
            }
        }
 
        System.out.println(res);





输出结果:{3=2, 4=1}
转自:https://blog.csdn.net/xuejingfu1/article/details/54410339

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM