I have the below requirement, I have 2 Lists, one is EmployeeList and DepartmentList now I want to merge/append the 2 lists into another List(finalList) based on the fields in the example below.
List<Employee> list = List.of( new Employee(1,"aba",101),
new Employee(2,"cdc",102),new Employee(3,"ded",102));
List<Department> list1 = List.of( new Department(101,"Dep1"),
new Department(102,"Dep2"));
List <EmployeeDepartment> finalList = List.empty();
Below are the classes: Employee
, Department
and EmployeeDepartment
.
public class EmployeeDepartment {
Integer deptno;
Integer empid;
String empname;
---setters and Getters
}
public class Department {
Integer deptno;
String depname;
---setters and Getters
}
public class Employee {
Integer empid;
String empname;
Integer deptno;
---setters and Getters
}
You may iterate on both lists and add the new
EmployeeDepartment
objectsOr using
Stream