java - building a new array to organize data based off of common index
<p>This is a simple issue I am just having trouble finding the right terms to use for google help. I have some java code that loops some data and I end up having two pieces of information: an <code>int</code> id, and an <code>int</code> quantity.</p>

<p>However, sometimes the ids are the same, and I want to combine the quantities if they are, rather than having new entries in an array.</p>

<p>In PHP, I would do this as such (assume <code>$products</code> is an array with lots of <code>id</code>/<code>quant</code> data, of course):</p>

<pre><code>$newArray = array();
for($products as $id &gt; $quant){
    if(array_key_exists($id, $newArray)){
        $newArray[ $id ] += $quant;
    } else {
        $newArray[ $id ] = $quant;
    }
}
</code></pre>

<p>I'm trying to do this in Java but nothing I find seems to help. </p>
