Java ArrayList remove() unexpected result?
<p>Here is my code</p>

<pre><code>void reduce() {
    KeyVal reducer1 = new KeyVal();
    for (int i=0; i&lt; m1.size(); i++) {
        reducer1.setKey(m1.get(i).getKey());
        reducer1.setValue(m1.get(i).getValue());

        for (int j=i+1; j &lt; m1.size(); j++) {
              if (m1.get(i).getKey().compareTo(m1.get(j).getKey()) == 0) {
                  m1.remove(j);
                  //System.out.println(i + "--&gt;" + j);
                  reducer1.setValue(reducer1.getValue() + 1);
              }
          }         

        System.out.println(reducer1.getKey());
        System.out.println(reducer1.getValue());
        //r1.add(reducer1);
      }
</code></pre>

<p>It's basically for counting no. of occurrences of particular entry.
If i am giving input</p>

<pre><code>3494702579
3494702579
3494702579
</code></pre>

<p>I am getting </p>

<pre><code>3494702579
2
3494702579
1
</code></pre>

<p>But I should get</p>

<pre><code>3494702579
3
</code></pre>

<p>What am I doing wrong?</p>
