jdk8 stream 去重
作者:互联网
public static void main(String[] args) {
List<Map<String, String>> objects = new ArrayList<>();
Map<String, String> map = new HashMap<>();
map.put("C_CONT_ID","123");
map.put("c_Ri_Com","456");
Map<String, String> map1 = new HashMap<>();
map1.put("C_CONT_ID","123");
map1.put("c_Ri_Com","789");
Map<String, String> map2 = new HashMap<>();
map2.put("C_CONT_ID","1111");
map2.put("c_Ri_Com","456");
Map<String, String> map3 = new HashMap<>();
map3.put("C_CONT_ID","ooooo");
map3.put("c_Ri_Com","ppppp");
Map<String, String> map4 = new HashMap<>();
map4.put("C_CONT_ID","123");
map4.put("c_Ri_Com","456");
objects.add(map);
objects.add(map1);
objects.add(map2);
objects.add(map3);
objects.add(map4);
System.out.println(objects.toString());
List<Map<String, String>> distinctMaps = objects.parallelStream().distinct()
.collect(Collectors.toList());
System.out.println(distinctMaps.toString());
}
运行 查看结果
去重前 : [{c_Ri_Com=456, C_CONT_ID=123}, {c_Ri_Com=789, C_CONT_ID=123}, {c_Ri_Com=456, C_CONT_ID=1111}, {c_Ri_Com=ppppp, C_CONT_ID=ooooo}, {c_Ri_Com=456, C_CONT_ID=123}]
去重后 : [{c_Ri_Com=456, C_CONT_ID=123}, {c_Ri_Com=789, C_CONT_ID=123}, {c_Ri_Com=456, C_CONT_ID=1111}, {c_Ri_Com=ppppp, C_CONT_ID=ooooo}]
标签:CONT,stream,456,ID,jdk8,put,Com,Ri 来源: https://blog.csdn.net/lx853771701/article/details/120225750