利用java中迭代器实现 循环遍历输出List<List<List<List<List<Map<String,Map<String,List<String>>>>>>>>中的值
时间: 2023-07-09 15:51:12 浏览: 139
可以使用嵌套的迭代器来实现循环遍历输出List<List<List<List<List<Map<String,Map<String,List<String>>>>>>>>中的值。具体代码如下:
```
List<List<List<List<List<Map<String,Map<String,List<String>>>>>>>> list = new ArrayList<>(); // 假设这是需要遍历的列表
// 获取迭代器
Iterator<List<List<List<List<Map<String,Map<String,List<String>>>>>>>> iter1 = list.iterator();
while (iter1.hasNext()) {
List<List<List<List<Map<String,Map<String,List<String>>>>>>>> list1 = iter1.next();
Iterator<List<List<List<Map<String,Map<String,List<String>>>>>>> iter2 = list1.iterator();
while (iter2.hasNext()) {
List<List<List<Map<String,Map<String,List<String>>>>>> list2 = iter2.next();
Iterator<List<List<Map<String,Map<String,List<String>>>>>> iter3 = list2.iterator();
while (iter3.hasNext()) {
List<List<Map<String,Map<String,List<String>>>>> list3 = iter3.next();
Iterator<List<Map<String,Map<String,List<String>>>> iter4 = list3.iterator();
while (iter4.hasNext()) {
List<Map<String,Map<String,List<String>>>> list4 = iter4.next();
Iterator<Map<String,Map<String,List<String>>>> iter5 = list4.iterator();
while (iter5.hasNext()) {
Map<String,Map<String,List<String>>> map = iter5.next();
// 遍历Map中的键值对
for (Map.Entry<String,Map<String,List<String>>> entry : map.entrySet()) {
System.out.println("Key: " + entry.getKey());
Map<String,List<String>> subMap = entry.getValue();
// 遍历子Map中的键值对
for (Map.Entry<String,List<String>> subEntry : subMap.entrySet()) {
System.out.println("SubKey: " + subEntry.getKey());
List<String> subList = subEntry.getValue();
// 遍历子列表中的元素
for (String str : subList) {
System.out.println("Value: " + str);
}
}
}
}
}
}
}
}
```
阅读全文