Remove Data and Arraylist looping
<p>I have a object with 3 variable (id(string), year(int), pay(double))
I have created an arraylist that contains object.</p>

<p>So now I need to sum the the pay if they have the same id and year and store it in a new array! is that possible?</p>

<pre><code>   ArrayList&lt;Earning&gt; temp = new ArrayList();
ArrayList&lt;Earning&gt; temp = new ArrayList();

    double tempEarning = 0.0;
    int count = 0;


    for (int i = 0; i &lt; weeklyEarnings.size(); i++) {
        Earning e = weeklyEarnings.get(i);
        String id = e.getId();
        int year = e.getYear();
        tempEarning = e.getEarning();

        Earning e2 = weeklyEarnings.get(i + 1);

        if (id.equalsIgnoreCase(e2.getId()) &amp;&amp; year == e2.getYear()) {
            tempEarning += e2.getEarning();
        } else {
            Earning tempEarn = new Earning();

            tempEarn.setEarning(tempEarning);
            tempEarn.setId(id);
            tempEarn.setYear(year);

            temp.add(tempEarn);

            count++;


            tempEarning = 0.0;


        }

    }

    weeklyEarnings.clear();
    weeklyEarnings = temp;
    temp.clear();
</code></pre>

<p>Can someone Help me? Thanks a lot!</p>
