title: Algorithm for comparing two lists
body: <p>I have a list of objects that I am displaying on the screen.  The user can change them as they like, and then hit submit.  In the submit method I am taking the original list, which I stored, and the current list, and comparing them.  I have to create a third list that contains all the objects that were added, removed, or changed with an action code to specify which it was.  The objects have an id to identify them, which defaults to 0.</p>
  
  <p>How can I do this?  This is the best I could come up with (pseudocode) but it seems sloppy.</p>
  
  <pre><code>for (currentObject : objects in current list)
      if (currentObject.id is 0)
          //Was added
      for (oldObject : objects in original list)
          if (currentObject.id == oldObject.id)
              //Existed - compare other fields to see if changed
  
  for (oldObject1 : objects in original list)
      boolean existed = false;
      for (currentObject1 : objects in current list)
          if(oldObject1.id == currentObject1.id)
              existed=true;
      if (!existed)
          //Was removed
  </code></pre>