Q:

Java ArrayList remove duplicates from both the lists

I have 2 ArrayList of custom objects. I want to remove duplicate entries from both the ArrayList. 
The objects have three fields: fName, lName, and id. If the id occurs multiple times, I want to remove from both the lists.
How can I do that?
I am fine with merging both the lists and removing the 2 duplicate entries as well.

A:

If you want to merge: simply copy the content of both lists to a map. Then you don't have the duplicates anymore (but you loose your actual ordering):
Map<Integer, MyObject> temp = new HashMap<Integer, MyObject>();
for (MyObject obj:firstList) {
   temp.put(obj.getId(), obj);
}
for (MyObject obj:secondList) {
   temp.put(obj.getId(), obj);
}
List<MyObject> result = new ArrayList<MyObject>(temp.values());

