Nested HashMap:
HashMap<String,HashMap<String,String>> outerMap=new HashMap<String, HashMap<String, String>>();
HashMap<String,String> innerhashMap=new HashMap<String, String>();
innerhashMap.put("aaa","AAA");
outerMap.put("111",innerhashMap);
innerhashMap.put("aaa","AAA");
outerMap.put("222",innerhashMap);
I want outer map keys list,inner map keys list and innermap values list
for ( String outerkey : outerMap.keySet() ) {
HashMap<String,String> innerHashMap = (HashMap<String,String>) outerMap.get(outerKey)
for ( String innerKey : innerHashMap.keySet() ) {
String innerValue = (String) innerHashMap.get(innerKey);
//... Process them
}
}
HashMap<String,HashMap<String,String>> outerMap = new HashMap<>();
HashMap<String,String> innerhashMap = new HashMap<>();
innerhashMap.put("aaa","AAA");
outerMap.put("111",innerhashMap);
innerhashMap.put("aaa","AAA");
outerMap.put("222",innerhashMap);
outerMap.forEach((k, v) -> {
System.out.println("OUTER KEY: " +k);
v.forEach((kk, vv) -> {
System.out.println("INNER KEY: " +kk+ " INNER VALUE: " +vv);
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.