HashMap获取重复的value值

HashMap<String,String> map= new HashMap<>();
        map.put("dsadf","张三");
        map.put("vdsfa","李四");
        map.put("dsadv","王五");
        map.put("dasda","李四");
        map.put("djgdf","李五");
        map.put("ngsdf","李四");

        System.out.println("提取前:"+map);

        HashMap<String, String> mapnew = new HashMap<>();
        HashMap<String, String> mapnew2 = new HashMap<>();
        map.forEach((k,v)->{
            if(!mapnew.containsValue(v)){
                mapnew.put(k,v);
            }else{
                mapnew2.put(k,v);
            }
        });

        System.out.println("不重复的值:"+mapnew);
        System.out.println("重复的值:"+mapnew2);

 

© 版权声明
THE END
喜欢就支持以下吧
点赞10赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片