title: HashMap getting unintended string for key value
body: <p>I have this piece of code :</p>
  <pre><code>private static void addItem(String[] commandParsed, Set&lt;Item&gt; inventory, Map&lt;String, Map&lt;String, Item&gt;&gt; maps) {
          Item item = new Item(commandParsed[1], Double.parseDouble(commandParsed[2]), commandParsed[3]);
          String mapName = commandParsed[3];
          Map&lt;String, Item&gt; map = new HashMap&lt;&gt;();
          if (inventory.contains(item)) {
              System.out.printf(&quot;Error: Item %s already exists%n&quot;, item.name);
          } else {
              inventory.add(item);
              System.out.printf(&quot;Ok: Item %s added successfully%n&quot;, item.name);
               maps.computeIfAbsent(mapName, k -&gt; new HashMap&lt;&gt;()).put(item.name, item);
          }
      }
  </code></pre>
  <p>my Idea is to add all unique items to a set and then to make  <code>Map&lt;String, Map&lt;String, Item&gt;&gt; maps</code> where the key is the type of the added item and the value to be map containing all items of that type, but the key to be the Item names. However the keys of the inner maps are again the type of the item. here is some sample input</p>
  <pre><code>add CowMilk 1.90 dairy
  add BulgarianYogurt 1.90 dairy
  </code></pre>
  <p>I am trying to find out why my inner map <code>key-value pair</code> is not <code>&lt;item.name, Item&gt;</code> but <code>&lt;item.type, Item&gt;</code> since my code is <code>.put(item.name, item);</code></p>
  <p>This is my Item class constructor</p>
  <pre><code> public Item(String name, double price, String type) {
          this.name = name;
          this.price = price;
          this.type = type;
      }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/kVBpU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kVBpU.png" alt="enter image description here" /></a></p>