[英]how to iterate Map<String, List<Map<String, Object>>> in java?
I have a method which is returning Map<String, List<Map<String, Object>>>
我有一个方法返回Map<String, List<Map<String, Object>>>
How to iterate over a map like Map<String, List<Map<String, Object>>>
如何迭代像Map<String, List<Map<String, Object>>>
这样的Map<String, List<Map<String, Object>>>
You would iterate over it like you would iterate over every other map.你会像迭代其他所有地图一样迭代它。 You just need to "recursively" iterate over the List and another Aap inside the iteration loop.您只需要在迭代循环中“递归地”迭代 List 和另一个 Aap。
One possible way (without functional code):一种可能的方式(没有功能代码):
Map<String, List<Map<String, Object>>> yourMap = ...;
//iterate over outer map
for(Map.Entry<String, List<Map<String, Object>>> topEntry : yourMap.entrySet()) {
String topKey = topEntry.getKey();
//iterate over list
for(Map<String, Object> innerMap : topEntry.getValue()) {
//iterate over inner map
for(Map.Entry<String, Object> innerEntry : innerMap.entrySet()) {
String innerKey = innerEntry.getKey();
Object innerValue = innerEntry.getValue();
}
}
}
You can also switch the foreach loop iterating over the List to a fori loop [ for(int i=0; i<list.size(); i++)
] if you need to know the list-index.如果您需要知道列表索引,您还可以将遍历 List 的 foreach 循环切换为 fori 循环 [ for(int i=0; i<list.size(); i++)
]。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.