Java8 stream 对List<Map<String,Object>> 去重
List<Map<String,Object>> list1 = new ArrayList<>();
Map<String,Object> map = new HashMap();
Map<String,Object> map2 = new HashMap();
map.put("key","1");
map.put("value","a");
map2.put("key","2");
map2.put("value","a");
list1.add(map);
list1.add(map2);
list1.forEach(System.out::println);
List<Map<String, Object>> list2 = list1.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(
() ->new TreeSet<>(Comparator.comparing(m->m.get("value").toString()))
),ArrayList::new
)
);
System.out.println("--------");
list2.forEach(System.out::println);