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