title: Java adjusting nested Hashmap value
body: <p>I was trying to use ideas given here to adjust a nested hashmap but my solution does not work: <a href="https://stackoverflow.com/questions/4157972/how-to-update-a-value-given-a-key-in-a-java-hashmap">How to update a value, given a key in a java hashmap?</a>. My nested hashmap is <code>shoppingLists</code>. It contains an outer hashmap of shopping list <code>listID</code> as key and a hashmap of items as values. The items hashmap contains <code>itemName</code> as key and the amount of the item as the value. The <code>adjustItemAmount</code> attempts to adjust the amount of an item by a given amount <code>x</code>.</p>
  
  <pre><code>HashMap&lt;String, HashMap&lt;String, Integer&gt;&gt; shoppingLists = new HashMap&lt;&gt;();
  
  public void adjustItemAmount(String itemName, int x, String listID) {
    int current_amount = shoppingLists.get(listID).get(itemName);
    HashMap&lt;String, Integer&gt; items = shoppingLists.get(listID);
    HashMap updatedItems = items.put(itemName, items.get(itemName) + x);
    shoppingLists.put(listID, updatedItems);
  }
  </code></pre>
  
  <p>The line <code>HashMap updatedItems = items.put(itemName,items.get(itemName)+x);</code> states that Java expects a hashmap but gets an integer. I do not see how that is the case.</p>