title: Java 8 Streaming: Grouping with aggregation
body: <p>I have some trouble finding a good approach/implementation using the Stream API for the following:</p>
  
  <p>I have a list of elements, each element consisting of a string and an integer. Now I like to group the elements by their string values, and then for each group I like to have the sum of the integer values from the elements that relate to that group.  </p>
  
  <p>Example: I have the following 3 elements:</p>
  
  <pre><code>("GroupA", 100) ("GroupA", 50) ("GroupB", 10)
  </code></pre>
  
  <p>And as a result I like to get a map consisting of the following two (key,value) pairs:</p>
  
  <pre><code>("GroupA, 150) ("GroupB, 10)
  </code></pre>
  
  <p>I'm not sure how to solve this. The most promising I came up with so far is this:</p>
  
  <pre><code>elements.stream().collect(Collectors.groupingBy(e-&gt; e.getGroup()))
              .merge(group, elementsOfTheGroup, (...));
  </code></pre>
  
  <p>But I'm not sure what function to insert as the last parameter of the merge method. But I don't know if I should even use the merge method.</p>
  
  <p>What would be the most elegant implementation for this?</p>