I have two list of Objects. I have framed this list by querying the database.
For Ex:
List<Employee> firstList={holDate,holName,createdby,empId}
List<Employee> seconList={holDate,holName,createdby,empId}
Now, I need to compare holDate, holName of firstList with holDate, holName of secondList. If holDate, holName of firstList not found in secondList, I need to add that in separate list.
The list may be in any order.
NOTE: empId is a primary key column.
Update - what I've tried:
for(Employee emp:firstList) {
for(Employee tgtEmp:seconList) {
if((emp.getHolDate()!=tgtEmp.getHolDate())&& (emp.getHolName()!=tgtEmp.getHolName())){
printList.add(emp); break;
}
}
}
Sample List Values:
firstList={{2015-08-15,"Independence Day","e1","Empl"},{2015-01-26,"Republic Day","e1","Empl"},{2015-09-20,"Memorial Day","e1","Empl"}}
seconList={{2015-08-15,"Independence Day","e1","Emp2"},{2015-10-25,"Thanks Giving Day","e1","Emp2"}}
Here, newlist should have all the values which is available in seconList and "RepublicDay","MemorialDay" from firstList
Employee? Does it have a customequalsandhashcodemethod, cause it would really easy then to just useList#removeAllorList#retainAllto identify the duplicates. Of course, you could just both of them into some kind ofSet...