How to access nested hashmap value? | SoloLearn: Learn to code for FREE!


How to access nested hashmap value?

Map<String , Map<String, Object>>

1/19/2017 5:34:01 PM

Faruque Hossain

4 Answers

New Answer


If you have it defined like this: Map<String , Map<String, Integer>> map1 = HashMap<>(); You can get value from inner map like this: Object value = map1.get("outerKey").get("innerKey"); which is equal to Map<String, Object> innerMap = map1.get("outerKey"); Object value = innerMap.get("innerKey");


I got better one here... Map<Float, Map<Float, Integer>> map = new HashMap<>(); map.put(.0F, new HashMap(){{put(.0F,0);}}); map.put(.1F, new HashMap(){{put(.1F,1);}}); map.get(.0F).get(.0F);


Thank you...


How can I read the integer value only from the inner Map?