Why cant I get a reference to a value in a map? : <p>I am quite confused about everything being a reference in most cases but sometimes not, and containers. Consider this piece of code:</p>

<pre><code>HashMap&lt;Integer,String&gt; x_map = new HashMap&lt;&gt;();
x_map.put(42,"foo");
String g = x_map.get(42);
g = "bar";
System.out.println(g.equalsIgnoreCase(x_map.get(42)));
</code></pre>

<p>Why does this print <code>false</code> ?</p>

<p>I found the correct way to do it: 
<a href="https://stackoverflow.com/questions/4157972/how-to-update-a-value-given-a-key-in-a-java-hashmap?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa">How to update a value, given a key in a java hashmap?</a>, but I am totaly lost why the above does not work as expected. Also when the objects in the map are rather large then I would like to be able to modify only a single member of one of the values in the map and currently I dont know how to do that without creating a new instance and put that into the map.</p>
