求救!为什么filter对比两个对象List差分不出值来
代码如下:
public static void main(String[] args) {
// Create two lists of Person objects
List<Person> list1 = new ArrayList<>();
list1.add(new Person("Alice", 25));
list1.add(new Person("Bob", 30));
list1.add(new Person("Charlie", 35));
List<Person> list2 = new ArrayList<>();
list2.add(new Person("Bob", 30));
list2.add(new Person("Charlie", 35));
list2.add(new Person("Dave", 40));
// Calculate the difference between the two lists
List<Person> difference = list1.stream()
.filter(person -> !list2.contains(person))
.collect(Collectors.toList());
System.out.println("The difference between the two lists is:");
difference.forEach(System.out::println);
}
但是difference类差分出的结果还是三条?为什么?为什么?为什么?
![在这里插入图片描述]
(https://img-blog.csdnimg.cn/d05ff4733bce41269c0b685df1debfa5.png)