java以及jstl表达式中对HashMap的迭代

来源:互联网 发布:秦国 知乎 编辑:程序博客网 时间:2024/06/06 14:07

 

①java

entrySet()返回此映射所包含的映射关系的Set视图,即key-value的set集合,类型是Set<Map.Entry<K,V>>

HashMap<String, Object> map = new HashMap<String, Object>();
map.put("001", "xy001");
map.put("002", "xy002");
Set<Map.Entry<String, Object>> entrySet = map.entrySet();
for (Map.Entry<String, Object> entry : entrySet)
{
System.out.println(entry.getKey() + "..." + entry.getValue());
}

 

②JSTL

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

 

 

原创粉丝点击