差集
List<Person> reduce1 = list1.stream().filter(
a -> !list2.stream().map(
b -> b.getAge() + "&" + b.getName()).collect(Collectors.toList())
.contains(a.getAge() + "&" + a.getName())).collect(Collectors.toList());
reduce1.parallelStream().forEach(System.out :: println);
System.out.println("=============================得到差集 reduce2 (list2 - list1)==================================");
List<Person> reduce2 = list2.stream().filter(
a -> !list1.stream().map(
b -> b.getAge() + "&" + b.getName()).collect(Collectors.toList()).contains(a.getAge() + "&" + a.getName()))
.collect(Collectors.toList());
reduce2.parallelStream().forEach(System.out :: println);
交集
List<Person> intersectA = list1.stream().filter(
a -> list2.stream().map(
Person::getName).anyMatch(
name -> Objects.equals(a.getName(), name)))
.collect(Collectors.toList());
intersectA.parallelStream().forEach(System.out :: println);
过滤
Map<Object, Boolean> map = new HashMap<>();
List<Person> list8 = list1.stream()
.filter(i -> map.putIfAbsent(i.getName()+"&"+i.getAge(), Boolean.TRUE) == null).collect(Collectors.toList());