我有两个数组列表。每个都有 Employee 类型的对象列表。
Employee 类如下所示
public class Employee {
private int id; // this is the primary key from employee table
private String firstname;
private String lastname;
private String employeeId; // manually assigned unique id to each employee
private float fte;
Employee(String firstname, String lastname, String employeeId, float fte) {
this.firstname = firstname;
this.lastname = lastname;
this.employeeId = employeeId;
this.fte = fte;
}
// getters and setters
}
员工 ID 是手动生成的给每个员工的唯一 ID。
我需要根据具有不同 fte 的员工 id 找到两个列表之间的共同员工。
import java.util.ArrayList;
import java.util.List;
public class FindFTEDifferencesBetweenMatchingEmployeeIds {
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", 1));
list1.add(new Employee("F2", "L2", "EMP02", 1));
list1.add(new Employee("F3", "L3", "EMP03", 1));
list1.add(new Employee("F4", "L4", "EMP04", 1));
list1.add(new Employee("F5", "L5", "EMP05", 1));
list1.add(new Employee("F9", "L9", "EMP09", 0.7F));
list2.add(new Employee("F1", "L1", "EMP01", 0.8F));
list2.add(new Employee("F2", "L2", "EMP02", 1));
list2.add(new Employee("F6", "L6", "EMP06", 1));
list2.add(new Employee("F7", "L7", "EMP07", 1));
list2.add(new Employee("F8", "L8", "EMP08", 1));
list2.add(new Employee("F9", "L9", "EMP09", 1));
List<FTEDifferences> commonInBothListWithDifferentFTE = new ArrayList<FTEDifferences>();
// this should contain EMP01 and EMP09
// since EMP02 has same FTE in both lists, it is ignored.
}
}
员工 ID 为 EMP01 和 EMP09 的员工在这两个列表中都很常见,而且他们在每个列表中也有不同的 ftes。
所以,我想要另一个包含这两名员工的列表。
public class FTEDifferences {
private Employee fromList1;
private Employee fromList2;
public Employee getFromList1() {
return fromList1;
}
public void setFromList1(Employee fromList1) {
this.fromList1 = fromList1;
}
public Employee getFromList2() {
return fromList2;
}
public void setFromList2(Employee fromList2) {
this.fromList2 = fromList2;
}
}
请帮忙。
PS。即使在 SQL 中执行此操作很容易,但我无法在 SQL 查询中执行此操作,因为我无法修改查询。我只需要处理两个给定的列表。:(