list里面有map,怎么遍历出来?

ArrayList list = new ArrayList();
Map map = new HashMap();
list.add(map);
怎么遍历得到map的键及key

第1个回答  2011-10-09
ArrayList<Map> list = new ArrayList<Map>();
for(int i = 0; i < list.size(); i++) {
Map map = list.get(i);
Set set = map.keySet();
Iterator it = set.iterator();
while(it.hasNext()) {
System.out.println(map.get(it.next()));
}
}本回答被提问者采纳
第2个回答  推荐于2018-02-27
看API。
for (Map map : list) {
Set set = map.keySet();
Iterator it = set.iterator();
while (it.hasNext()) {
Object key = it.next();
Object value = map.get(key);
}
}本回答被网友采纳
第3个回答  2018-03-31

这样可以把三类map的value都分别显示出来?
List> result = null;

Map<String,String> asset = new HashMap<>();
Map<String,String> num = new HashMap<>();
Map<String,String> rank = new HashMap<>();

<c:forEach items="${dataList}" var="mapData">
<c:forEach items="${mapData}" var="map">
<c:out value="${map.key}"></c:out>:<c:out value="${map.value}"></c:out>
</c:forEach>
</c:forEach>

Map map = (Map)list.get(0);String str = (String)map.get("w");//str就是22

本回答被网友采纳
相似回答