遍历List<Map<String,String>>
时间: 2023-06-01 14:03:35 浏览: 139
FreeMarker 遍历list<map;string>
可以使用for循环遍历List,再使用for循环遍历Map,如下所示:
```
List<Map<String, String>> list = new ArrayList<>();
// 添加元素
Map<String, String> map1 = new HashMap<>();
map1.put("name", "张三");
map1.put("age", "18");
list.add(map1);
Map<String, String> map2 = new HashMap<>();
map2.put("name", "李四");
map2.put("age", "20");
list.add(map2);
// 遍历
for (Map<String, String> map : list) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
System.out.println(key + ":" + value);
}
}
```
输出结果:
```
name:张三
age:18
name:李四
age:20
```
阅读全文