title: Java : Get Data from Nested HashMap
body: <p>Hi Folks i have looked at below mention question for answer but it was not helpful as they give answer for static value while i need to get value from dynamic approch</p>
  
  <p><a href="https://stackoverflow.com/questions/14582596/how-to-put-get-values-into-from-nested-hashmap">How to put/get values into/from Nested HashMap</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10607287/getting-value-from-nested-hashmap-into-another-map">Getting value from Nested HashMap into another Map</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2774608/how-do-i-access-nested-hashmaps-in-java">How do I access nested HashMaps in Java?</a></p>
  
  <p><strong>This is my Scenario :</strong></p>
  
  <p>This is my class for adding and retrieving data from HashMap :-</p>
  
  <pre><code>HashMap&lt;Integer, String&gt; xmlQueryNode = new HashMap&lt;Integer, String&gt;();
  HashMap&lt;Integer, HashMap&lt;Integer, String&gt;&gt; splunkHashMap = new HashMap&lt;Integer, HashMap&lt;Integer, String&gt;&gt;();
  id = 0;
  xmlQueryNode.put(0, "F0name");
  xmlQueryNode.put(1, "L0name");
  xmlQueryNode.put(2, "M0name");
  
  splunkHashMap.put(id, xmlQueryNode);
  
  id = 1;
  xmlQueryNode.put(0, "F1name");
  xmlQueryNode.put(1, "L1name");
  xmlQueryNode.put(2, "M1name");
  
  splunkHashMap.put(id, xmlQueryNode);
  
  id = 2;
  xmlQueryNode.put(0, "F2name");
  xmlQueryNode.put(1, "L2name");
  xmlQueryNode.put(2, "M2name");
  
  splunkHashMap.put(id, xmlQueryNode);
  
  id = 3;
  xmlQueryNode.put(0, "F3name");
  xmlQueryNode.put(1, "L3name");
  xmlQueryNode.put(2, "M3name");
  
  splunkHashMap.put(id, xmlQueryNode);
  
  for (Integer key : splunkHashMap.keySet()) {
      HashMap&lt;Integer, String&gt; temp =  new HashMap&lt;Integer, String&gt;();
      //System.out.println(key);
      temp = otsdbQueryData.get(key);
      for(Integer key1: temp.keySet()){
          System.out.println(temp.get(key1));
      }
  }
  </code></pre>
  
  <p>Problem with this code is that i get below output for all 4 entries :-</p>
  
  <pre><code>F3name
  L3name
  M3name
  
  F3name
  L3name
  M3name
  
  F3name
  L3name
  M3name
  
  F3name
  L3name
  M3name
  </code></pre>
  
  <p>Can anyone point me where i am making mistake because My hashmaps are being overwritten by last inserted hashmap??</p>