Java:map< string,map< string,integer>> [英] Java: map<string, map<string, integer>>

查看:143
本文介绍了Java:map< string,map< string,integer>>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个

I have this

Map<String, Map<String, Integer>>



I想要迭代地图的地图,每个地图中的一个元素。

例如:


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





< b>我尝试了什么:





What I have tried:

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

推荐答案

只需使用此代码即可使用地图地图。



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);
        }


这篇关于Java:map&lt; string,map&lt; string,integer&gt;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆