title: Comparing key and values of two java maps
body: <p>I'm still relatively new to Java and I'm finding myself stuck on trying to properly write this piece of code that I feel should be a bit more simple.</p>
  
  <p>I have two maps made up of two different instances of the same object.  The keys are objects, and the values are objects.</p>
  
  <p>There are two instances because I'm trying to determine if the keys in one instance are different from the keys in another instance.  I'm trying to specifically locate new keys or missing keys, and then compare the values of the keys which exist in both maps.  </p>
  
  <p>The sample code below is just to help visualize what I'm trying to do (hopefully it's not more confusing!)</p>
  
  <p>The goal of the below example should tell me that key "C" is missing and there is a new key ("D") and then it should finally compare the values of keys in both maps.</p>
  
  <p>Main question is, is there anyway to do this in one loop?  Primarily because my actual code will touch the file system for the values in the map and I'm trying to minimize the times it has to touch the disk</p>
  
  <pre><code>Map&lt;objA, objB&gt; mapA = new HashMap&lt;objA, objB&gt;();
  mapA.put("A", "1");
  mapA.put("B", "2");
  mapA.put("C", "3");
  
  Map&lt;objA, objB&gt; mapB = new HashMap&lt;objA, objB&gt;();
  mapB.put("A", "1");
  mapB.put("D", "4");
  
  // Check if something is missing from mapB
  for(Map.Entry&lt;objA, objB&gt; entryMapA:mapA.entrySet())
  {
      if(!mapB.containsKey(entryMapA.getKey())
          {
              System.out.println(entryMapA.getKey() + " is missing");
          }
  }
  
  // Check if something is new is in mapB
  for(Map.Entry&lt;objA, objB&gt; entryMapB:mapB.entrySet())
  {
      if(!mapA.containsKey(entryMapB.getKey())
      {  
          System.out.println(entryMapB.getKey() + " is new");
      }
  }
  </code></pre>