title: How do I remove duplicate objects from two separate ArrayLists?
body: <p>Before beginning, I think that this question has a very simple answer that I'm just overlooking. I figured a few more eyes on the question at hand will be able to point out my problem fairly quickly.</p>
  
  <p>I have two ArrayLists that I want to compare and remove duplicates from each of them. The first <code>ArrayList</code> is an <code>ArrayList</code> of older information where as the second <code>ArrayList</code> contains the new information.</p>
  
  <p>Like so</p>
  
  <pre><code>ArrayList&lt;Person&gt; contactList = new ArrayList();
  contactList.add(new Person("Bob");
  contactList.add(new Person("Jake");
  contactList.add(new Person("Joe");
  ontactList.add(new Person("Rob");
  
  ArrayList&lt;Person&gt; updatedContactList = new ArrayList();
  updatedContactList.add(new Person("Bob");
  updatedContactList.add(new Person("Jake");
  updatedContactList.add(new Person("Joe");
  updatedContactList.add(new Person("Phil");
  </code></pre>
  
  <p>My <code>Person</code> class is very simple, created solely for this example</p>
  
  <pre><code>public class Person {
      private String name;
  
      public Person(String a_name) {
          name = a_name;
      }
  
      public String getName() {
          return name;
      }
  }
  </code></pre>
  
  <p>So, using the above examples, I want to remove all duplicates. I'm trying keep it to just the two ArrayLists if possible, but am willing to do a deep clone of one of the ArrayLists if I have to.</p>
  
  <p>So I want the resulting <code>ArrayList</code> to have the following information in it once the comparison is done</p>
  
  <pre><code>contactList           //removed Person
      - Rob
  
  updatedContactList    //new Person
      - Phil
  </code></pre>
  
  <p>Here is the code I've put together</p>
  
  <pre><code>for(int i = 0; i &lt; contactList.size(); i++) {
      for(int j = 0; j &lt; updatedContactList.size(); j++) {
  
          if(contactList.get(i).getName().equals(updatedContactList.get(j).getName())) {
              //removed friends                    
              contactList.remove(contactList.get(i));
  
              //new friends ---- only one at a time works
              //updatedContactList.remove(updatedContactList.get(j));
          }
      }
  }
  </code></pre>
  
  <p>I'm only able to remove a Person from one of the ArrayLists in the above loop otherwise I get incorrect results.</p>
  
  <p>So my question is, is there an easy way to remove the duplicated elements from both ArrayLists? If so, how do I go about it.</p>
  
  <p>I realize that I could probably deep clone the updated <code>ArrayList</code> and just remove the objects from that one, but I'm wondering if there is a way without having to clone it.</p>
  
  <p>I also realize that I could just stuff all the elements into a Set and it would remove the duplicates, but I want to keep the 'removed' and 'new' Person objects separate.</p>