public static void removeDuplicateMap() {
//给出一个value有重复元素的map
Map<String,String> map = new HashMap<String, String>();
map.put("a", "aaa");
map.put("b", "aaa");
map.put("c", "bbb");
map.put("d", "ccc");
System.out.println("去重前"+map.toString());

//创建一个新的map2
Map<String,String> map2=new HashMap<String, String>();
for(String key:map.keySet()){
if(!map2.containsValue(map.get(key))){
map2.put(key, map.get(key));
}
}
System.out.println("去重后"+map2.toString());
}

转自:https://blog.csdn.net/weixin_41043652/article/details/80607104

posted on 2020-07-29 17:31  一贯可乐  阅读(989)  评论(0编辑  收藏  举报



123