Click here to Skip to main content
15,742,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this
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:

What I have tried:

for (Map.Entry<String, Map<String, Integer>> team : map.entrySet()) {
                for (Map.Entry key : team.getValue().entrySet()) {

But this solution print like that:

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

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