title: Combining two hashmaps with the same key and same or different values
body: <p>I have two hashmaps that I need to merge.</p>
  
  <pre><code>MAP 1 - [[LOCATION: United Kingdom], [PERSON: Alfred Theodore MacConkey], [ORGANIZATION: Royal Commission, United]]
  
  MAP 2 -{LOCATION=[United Kingdom], ORGANIZATION=[Royal Commission], PERSON=[Alfred Theodore MacConkey]}
  </code></pre>
  
  <p>If I create Map 3 and do an addAll() some values get overwritten. Like in case of ORGANIZATION I only get Royal Commission and United gets overwritten. I wrote a merge code for the two but get a null pointer exception. I just want to know if this approach is correct. I will debug and figure out why I am getting the exception.</p>
  
  <pre><code>public static  LinkedHashMap&lt;String,Vector&lt;String&gt;&gt; merge(HashMap&lt;String, Vector&lt;String&gt;&gt; a,  HashMap&lt;String, Vector&lt;String&gt;&gt; b) {
                     LinkedHashMap&lt;String,Vector&lt;String&gt;&gt; c = new  LinkedHashMap&lt;String,Vector&lt;String&gt;&gt;();
  
  
                     Set&lt;Entry&lt;String,Vector&lt;String&gt;&gt;&gt; entriesA = a.entrySet();
                     Set&lt;Entry&lt;String,Vector&lt;String&gt;&gt;&gt; entriesB = b.entrySet();
  
                      for (Map.Entry&lt;String, Vector&lt;String&gt;&gt; entry : entriesA ) {
  
                          Vector&lt;String&gt; aValues = a.get(entry.getValue());
                          String aKey =  entry.getKey();
  
                          Vector&lt;String&gt; allValues = entriesA.contains(aKey) ? a.get(aKey) : new Vector&lt;String&gt;();  
                          allValues.addAll(aValues);
  
                          c.put(aKey, allValues);
  
                      }
  
  
  
                      for (Map.Entry&lt;String, Vector&lt;String&gt;&gt; entry : entriesB ) {
                          Vector&lt;String&gt; bValues = b.get(entry.getValue());
                          String bKey =  entry.getKey();
  
                          if(c.containsKey(bKey) &amp;&amp; c.get(bKey).equals(bValues) ) {
                              continue;
                              } 
                          else if(c.containsKey(bKey) &amp;&amp; !(c.get(bKey).equals(bValues))) {
                              c.put(bKey, bValues); 
                        }
                      }
                      return c;
                  }
  </code></pre>