title: Sum of List<Integer, Integer> elements in Java
body: <p>I have an <code>ArrayList</code> which contain some <code>Integer values</code> as <code>Pairs</code>. I want to sum the <code>right</code> elements of the List where the left element is the same.</p>
  
  <p>For example, the input arrayList will contain: </p>
  
  <pre><code>final List&lt;Pair&lt;Integer, Integer&gt;&gt; a = new ArrayList&lt;&gt;();
  a.add(new Pair&lt;&gt;(1, 1));
  a.add(new Pair&lt;&gt;(2, 1));
  a.add(new Pair&lt;&gt;(2, 3));
  </code></pre>
  
  <p><code>New ArrayList should contain:</code></p>
  
  <p>As seen below:</p>
  
  <p>(common left value, sum of all the right values where left value is the same)</p>
  
  <pre><code>1, 1
  2, 4
  </code></pre>
  
  <p>Code I have written that doesn't return valid values:</p>
  
  <pre><code>for (int i=0; i&lt; a.size(); i++){
  
  
          //need help here
  }
  </code></pre>
  
  <p>EDIT: I want duplicate pairs so a HashMap won't work. </p>
  
  <p>Sorry for the edits.</p>