A little confused as to why my hashmap is updating. As an example, I have the below hashmaps:
Map<String, Integer> firstMap = new HashMap<String, Integer>();
Map<Integer, Map<String, Integer>> finalMap = new HashMap<Integer, Map<String, Integer>>();
Now, when I run this:
firstMap.put("Jason", 2);
finalMap.put(1, firstMap);
firstMap.put("Jason", 15);
finalMap.put(2, firstMap);
System.out.println(finalMap);
I get this:
{1={Jason=15}, 2={Jason=15}}
Why wouldn't I get this instead? This is what I want.
{1={Jason=2}, 2={Jason=15}}
Help is greatly appreciated, thanks!