how to sum hashmap values with same key java
<p>So I am having a problem where I have to add up all values with the same key in my HashMap. The data(petshop and pet price) is retrieve from an ArrayList. at the moment, the program only gets the last value for each shop since there are multiple shops with the same name but different pet price. I would like to be able to sum the pet price for each shop. so if we have for example, 
<br>Law Pet shop: 7.00 <br>and another Law Pet shop: 5.00, <br>I would like to output it like this: <br>Law Pet shop: 13.00. <br>Here is the code and output:</p>

<pre><code>public class AverageCost {

    public void calc(ArrayList&lt;Pet&gt; pets){

        String name = "";
        double price = 0;
        HashMap hm = new HashMap();

        for (Pet i : pets) {
            name = i.getShop();
            price = i.getPrice();

            hm.put(name, price);
        }

        System.out.println("");
        // Get a set of the entries
        Set set = hm.entrySet();
        // Get an iterator
        Iterator i = set.iterator();
        // Display elements
        while(i.hasNext()) {

            Map.Entry me = (Map.Entry)i.next();
            System.out.print(me.getKey() + ": ");
            System.out.println(me.getValue());
        }
    }
}
</code></pre>

<p>At the moment this is the output:</p>

<p>Aquatic Acrobatics: 7.06<br>
The Briar Patch Pet Store: 5.24<br>
Preston Pets: 18.11<br>
The Menagerie: 18.7<br>
Galley Pets: 16.8<br>
Anything Except Badgers: 8.53<br>
Petsmart: 21.87<br>
Morris Pets and Supplies: 7.12<br></p>