Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:08:46+00:00 2026-06-08T05:08:46+00:00

I have two array list. Each has list of Objects of type Employee. The

  • 0

I have two array list. Each has list of Objects of type Employee.

The Employee class looks like below

    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
}

Employee id is manually generated unique id given to each employee.

I need to find the common employees between the two lists based on a employee id which have different fte’s.

    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. 


    }
}

Employees with employee id EMP01 and EMP09 are common in both lists and they also have different ftes in each list.

So, I would want to have another list which contains these two employees.

    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;
    }
}

Please help.

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. 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:08:48+00:00Added an answer on June 8, 2026 at 5:08 am

    Override equals method like below.

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Employee other = (Employee) obj;
        if (employeeId == null) {
            if (other.employeeId != null)
                return false;
        } else if (!employeeId.equals(other.employeeId))
            return false;
        if (firstname == null) {
            if (other.firstname != null)
                return false;
        } else if (!firstname.equals(other.firstname))
            return false;
        if (Float.floatToIntBits(fte) == Float.floatToIntBits(other.fte))
            return false;
        if (lastname == null) {
            if (other.lastname != null)
                return false;
        } else if (!lastname.equals(other.lastname))
            return false;
        return true;
    }
    

    Then Create a finalList list and add list1 to it. Then call retainAll on finalList list with list2 which will give you common Employees based on employeeId

       List<Employee> finalList=new ArrayList<Employee>();
        finalList.addAll(list1);
        finalList.retainAll(list2);
        List<Employee> commonInBothListWithDifferentFTE=finalList;
        System.out.println(commonInBothListWithDifferentFTE);
    

    Output:

    [Employee [firstname=F1, lastname=L1, employeeId=EMP01, fte=1.0], Employee [firstname=F9, lastname=L9, employeeId=EMP09, fte=0.7]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two array list. Each has list of Objects of type Employee. The
I have a manager class maintaining a list of objects. Each Object has a
So we have a java class with two ArrayLists of generics. It looks like
I have a List<Employee> . Each Employee has a byte[] storing a picture (or
I have two arrays, each containing strings. The first array is a list of
I have an array of structs. The struct has two function pointers. Each element
I have a list of type List<Element<Integer, Integer>> , where each element contains two
I have two different arrays. One array, a, for a list of people. My
I have two List of array string. I want to be able to create
I have two classes, Foo and Bar. Each Foo has a name and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.