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
我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=270198dipw4ko
点赞10赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容