java - HashMap的HashMap->输出问题
问题描述
具有以下 HashMap:
HashMap <String, HashMap <Integer, ArrayList <Reservation> >>
缓冲区;我将输出两个哈希映射的每个键的每个值。我能怎么做?
我已经写了这部分代码:
HashMap map=mod.getAllRecords();
for (Object key: map.keySet()) {
String Date=key.toString();
Object map2=map.get(key);
for(Object Key : ??){//<--------------
}
解决方案
我知道的最简单的方法是编写三个 for 循环 - 首先是键元素本身已经是字符串,其次是第一个 HashMap 内的 HashMap 中的整数,第三个是第二个 HashMap 的每个数组内的值:
for (String key: map.keySet()) {
System.out.println(key); //prints the strings
HashMap <Integer, ArrayList <Reservation> > map2 = map.get(key);
for(Integer key2 : map2.keySet()){
System.out.println(key2); //prints the integers
for (int i=0;i<map2.get(key2).size();i++) {
System.out.println(map2.get(key2)[i]); //prints everything in the array
}
}
}
推荐阅读
- ios - 单击tableview标题按钮时如何将tableviewcell内的collectionview中的数据显示到另一个视图控制器
- r - R预测包中的动态回归
- python - 为什么我的请求返回一个空列表?
- docker - 在离线 Centos 服务器上安装 docker
- systemd - systemd:延迟发送 SIGTERM 两次,*然后*发送 SIGKILL?
- reactjs - 更新上下文时避免运行效果挂钩
- android - 无法解析配置“:app:debugRuntimeClasspath”的所有文件。对于谷歌广告
- pytorch - pytorch 中的一种热编码
- scanf - 为什么 scanf 在代码块 IDE 中无法正常工作
- python - 值错误。视图“users.views.register”没有返回 HttpResponse 对象。它返回 None 而不是