I have two arrayLists that contain objects of my Class Report Object. Report Object has couple of fields but most important are Tag(String) and Attr(String).
During the execution of the program two arrayLists are populated with that objects. These arrayLists represent old collection of the ReportObjects and the new one.
I want to know what objects were added to the new arrayList and what objects were removed from old ArrayList.
ReportObject obj1 = new ReportObject("Tag", "Attr", "XPath", "Parent", null);
ReportObject obj2 = new ReportObject("Tag2", "Attr", "XPath", "Parent", null);
ReportObject obj3 = new ReportObject("Tag", "Attr", "XPath", "Parent", null);
ArrayList<ReportObject> newList = new ArrayList<>();
ArrayList<ReportObject> oldList = new ArrayList<>();
ArrayList<ReportObject> added = new ArrayList<>();
ArrayList<ReportObject> removed = new ArrayList<>();
newList.add(obj1);
newList.add(obj2);
oldList.add(obj3);
added.addAll(newList);
added.removeAll(oldList);
Problem is I still have two elements in added ArrayList. That because obj1 and obj3 are different objects? When I do two loops and iterate over them while checking if objects has same field values i still get same results.
So in added arrayList I should have only obj2 and in removed arrayList should be empty.