比较两个list对象,1、找出相同ID,其他对象属性的值不相同的数据;2、找到不存在这个ID的

举个例子:
一个student对象,包含的属性有ID,name,age;
Student1.setID(1);
Student1.setName("张三");
Student1.setAge("20");
Student2.setID(2);
Student2.setName("李四");
Student2.setAge("30");
Student3.setID(3);
Student3.setName("王五");
Student3.setAge("40");
Student4.setID(1);
Student4.setName("王五");
Student4.setAge("20");
list1.add(student1);
list1.add(student2);
list1.add(student3);
list2.add(student4);
list2.add(student2);
以list1为基准,比较两个list对象,找出list2中没有的对象和找出list1中相同ID其他对象属性不相同的对象。
分别放到两个新的list中。
也就是找出相同ID,list1中作出修改的对象;list1中有,list2中没有的。
(还是昨天的问题,但是今天早上不知道怎么就不见了,所以又提了一下。)

 class Student {
...//现有代码
//加上
    @Override  
    public boolean equals(Object o) {  
        if (o == this) return true;  
        if (!(o instanceof Student)) {  
            return false;  
        }  
        Student s = (Student) o;  
        return s.getID() == this.getID(); 
    }  
    @Override  
    public int hashCode() {  
        return this.getID();
    }  
}

重写student类的equals和hashCode方法,两个都要重写。
然后list1.removeAll(list2); 求差集