Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this
Java
Map<String, Map<String, Integer>>

I want to iterate over Map of Map, by one element in each Map.
For example:
{as={qw=0, qr=2}, ew={asx=0, xvb=0, kl=5}}


I want to print like that:
qw,asx,qr,xvb,kl


What I have tried:

Java
for (Map.Entry<String, Map<String, Integer>> team : map.entrySet()) {
                for (Map.Entry key : team.getValue().entrySet()) {
                  System.out.print(key.getKey());
                }
         }


But this solution print like that:
qw,qr,asx,xvb,kl

This is not I want to achieve
Posted
Updated 3-Nov-17 2:01am
v3

1 solution

simply use this code for use map of map.

Map<String, Map<String, Integer>> outerMap = new HashMap<>();
        Map<String, Integer> innerMap = new HashMap<>();
        innerMap = outerMap.get(key);
        for(String innerKey : innerMap.keySet()){
         Integer innerValue = innerMap.get(innerKey);
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900