I have a list of arrays. Each has a list of objects of type Employee.
Employee class looks below
public class Employee {
Employee(String firstname, String lastname, String employeeId) {
this.firstname = firstname;
this.lastname = lastname;
this.employeeId = employeeId;
}
private int id;
private String firstname;
private String lastname;
private String employeeId;
}
I need to find the differences between the two lists based on the property of the employee object, which is the employee identifier.
The employee identifier assigns a unique identifier to each individual identifier.
import java.util.ArrayList;
import java.util.List;
public class FindDifferences {
public static void main(String args[]){
List<Employee> list1 = new ArrayList<Employee>();
List<Employee> list2 = new ArrayList<Employee>();
list1.add(new Employee("F1", "L1", "EMP01"));
list1.add(new Employee("F2", "L2", "EMP02"));
list1.add(new Employee("F3", "L3", "EMP03"));
list1.add(new Employee("F4", "L4", "EMP04"));
list1.add(new Employee("F5", "L5", "EMP05"));
list2.add(new Employee("F1", "L1", "EMP01"));
list2.add(new Employee("F2", "L2", "EMP02"));
list2.add(new Employee("F6", "L6", "EMP06"));
list2.add(new Employee("F7", "L7", "EMP07"));
list2.add(new Employee("F8", "L8", "EMP08"));
List<Employee> notPresentInList1 = new ArrayList<Employee>();
List<Employee> notPresentInList2= new ArrayList<Employee>();
}
}
source
share