title: How to find the common employees in two Array Lists which differ in one property?
body: <p>I have two array list. Each has list of Objects of type Employee. </p>
  
  <p>The Employee class looks like below</p>
  
  <pre><code>    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
  }
  </code></pre>
  
  <p>Employee id is manually generated unique id given to each employee.</p>
  
  <p>I need to find the common employees between the two lists based on a employee id which have different fte's. </p>
  
  <pre><code>    import java.util.ArrayList;
  import java.util.List;
  
  public class FindFTEDifferencesBetweenMatchingEmployeeIds {
  
      public static void main(String args[]) {
          List&lt;Employee&gt; list1 = new ArrayList&lt;Employee&gt;();
          List&lt;Employee&gt; list2 = new ArrayList&lt;Employee&gt;();
  
          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&lt;FTEDifferences&gt; commonInBothListWithDifferentFTE = new ArrayList&lt;FTEDifferences&gt;();
          // this should contain EMP01 and EMP09
          // since EMP02 has same FTE in both lists, it is ignored. 
  
  
      }
  }
  </code></pre>
  
  <p>Employees with employee id EMP01 and EMP09 are common in both lists and they also have different ftes in each list. </p>
  
  <p>So, I would want to have another list which contains these two employees. </p>
  
  <pre><code>    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;
      }
  }
  </code></pre>
  
  <p>Please help. </p>
  
  <p>PS. Even though it will be easy to do this in SQL, I can not do it in SQL query as I can not modify the queries. I only need to work with the two given lists. :( </p>