title: merge two Map Values in Java and if key is same append the Values not overwrite in Java 7 or Java 8
body: <p>I want to merge 2 <code>Map</code>s, but when the key is the same, the values should be appended instead of overwritten.</p>
  <p>Let's say</p>
  <pre class="lang-java prettyprint-override"><code>Map&lt;String, Set&lt;String&gt;&gt; map1 = new HashMap&lt;&gt;();
  Set&lt;String&gt; set1 = new HashSet&lt;&gt;();
  set1.add(&quot;AB&quot;);
  set1.add(&quot;BC&quot;);
  map1.put(&quot;ABCD&quot;,set1);
  
  Map&lt;String, Set&lt;String&gt;&gt; map2 = new HashMap&lt;&gt;();
  Set&lt;String&gt; set2 =new HashSet&lt;&gt;();
  set2.add(&quot;CD&quot;);
  set2.add(&quot;EF&quot;);
  map2.put(&quot;ABCD&quot;,set2);
  
  map1.putAll(map2);
  </code></pre>
  <p>So here the key is same.I know putAll will overwrite the values if key is same</p>
  <p>But I am looking for an output like</p>
  <pre><code>{ABCD=[AB,BC,CD,ED]}
  </code></pre>
  <p>If someone can help me to resolve, will be so thankful.</p>