public static void main(String[] args) {
List<Map<String, String>> list = new ArrayList<>();
Map<String, String> map = new HashMap<>();
Map<String, String> map1 = new HashMap<>();
Map<String, String> map2 = new HashMap<>();
map.put("name", "张三");
map.put("phone", "17600000001");
map1.put("name", "李四");
map1.put("phone", "17600000001");
map2.put("name", "王五");
map2.put("phone", "17600000002");
list.add(map);
list.add(map1);
list.add(map2);
List<Map<String, String>> result = new ArrayList<>();
for (Map<String, String> mapTemp : list) {
boolean b = result.stream().anyMatch(p -> p.get("phone").compareTo(mapTemp.get("phone")) == 0);
if (!b) {
result.add(mapTemp);
}
}
System.out.println(result.toString());
}
打印结果:[{phone=17600000001, name=张三}, {phone=17600000002, name=王五}]