title: Comparing two hashmap value with keys
body: <p>I have two <code>HashMaps</code>.</p>
  
  <pre><code>HashMap&lt;String, String&gt; hMap=new HashMap&lt;String, String&gt;();
  hMap.put("1","one");
  hMap.put("2", "two");
  hMap.put("3", "three");
  hMap.put("4", "four");
  
  HashMap&lt;String, String&gt; hMap2=new HashMap&lt;String, String&gt;();
  hMap2.put("one", "");
  hMap2.put("two", "");
  </code></pre>
  
  <p>I want to compare the key of hMap2 with hMap which are not equal I need to put it in another hashMap.For this I tried something like this.</p>
  
  <pre><code>HashMap&lt;String, String&gt; hMap3=new HashMap&lt;String, String&gt;();
  Set&lt;String&gt; set1=hMap.keySet();
  Set&lt;String&gt; set2=hMap2.keySet();
  
  Iterator&lt;String&gt; iter1=set1.iterator();
  Iterator&lt;String&gt; iter2=set2.iterator();
  String val="";
  while(iter1.hasNext()) {
  
      val=iter1.next();
      System.out.println("key and value in hmap is "+val+" "+hMap.get(val));
  
      iter2=set2.iterator();
  
      while(iter2.hasNext()) {
          String val2=iter2.next();
          System.out.println("val2 value is "+val2);
  
          if(!hMap.get(val).equals(val2)) {
              hMap3.put(val, hMap.get(val));
              System.out.println("value adding");
  
          }
      }
  }
  System.out.println("hashmap3 is "+hMap3);
  </code></pre>
  
  <p>The output I'm getting here is</p>
  
  <pre><code>hashmap3 is {3=three, 2=two, 1=one, 4=four}
  </code></pre>
  
  <p>My Expected output is</p>
  
  <pre><code>hashmap3 is {3=three, 4=four}
  </code></pre>
  
  <p>Please correct my logic.Thanks in advance</p>