title: how to merge a collection of Maps using streams
body: <p>I have a collection of maps: </p>
  
  <pre><code>Collection&lt;Map&lt;String,Double&gt;&gt; myCol = table.values();
  </code></pre>
  
  <p>I would like to transform this into a Map</p>
  
  <pre><code>Map&lt;String, Double&gt;
  </code></pre>
  
  <p>such that, for a matching key, values are summed up. Using a for loop, it is rather simple:</p>
  
  <pre><code>Map&lt;String, Double&gt; outMap = new HashMap&lt;&gt;();
  for (Map&lt;String, Double&gt; map : myCol) {
      outMap =  mergeMaps(outMap, map);
  }
  </code></pre>
  
  <p>and <code>mergeMaps()</code> is defined as </p>
  
  <pre><code>mergeMaps(Map&lt;String, Double&gt; m1, Map&lt;String, Double&gt; m2){    
      Map&lt;String, Double&gt; outMap = new TreeMap&lt;&gt;(m1);
      m2.forEach((k,v) -&gt; outMap.merge(k,v,Double::sum)); /*sum values if key exists*/
      return outMap;
  }
  </code></pre>
  
  <p>However, I would like to use streams to get a map from collection. I have tried as follows:</p>
  
  <pre><code>Map&lt;String, Double&gt; outMap = new HashMap&lt;&gt;();    
  myCol.stream().forEach(e-&gt; outMap.putAll(mergeMaps(outMap,e)));
  return outMap;
  </code></pre>
  
  <p>This works without a problem. However, can I still improve it? I mean, how can I use collectors in it?</p>