I have tried to store HashMap inside another HashMap but first inserted values changed as second time inserted value.
Here is my code.
HashMap<String ,HashMap<Integer ,Integer>> map1=new HashMap<>();
HashMap<Integer ,Integer> map2=new HashMap<>();
map2.put(1,1);
map2.put(2,1);
map2.put(3,1);
map1.put("1", map2);
System.out.println("After Inserting first value "+map1.entrySet());
/* OutPut: After Inserting first value [1={1=1, 2=1, 3=1}]*/
map2.clear(); //i cleared map 2 values
map2.put(4,2);
map2.put(5,2);
map2.put(6,2);
map1.put("2", map2);
System.out.println("After Inserting second value "+map1.entrySet());
/*output : After Inserting second value [2={4=2, 5=2, 6=2}, 1={4=2, 5=2, 6=2}]*/
The first time I got output as 1={1=1, 2=1, 3=1}]
after inserting second "key, value" [2={4=2, 5=2, 6=2}, 1={4=2, 5=2, 6=2}] I got key "1" values changed to key "2".