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