如何遍历map 如何在velocity遍历HashMap
如何遍历map
遍历Map的四种方法
public static void main(String[] args) {
Map
map.put("1", "value1")
map.put("2", "value2")
map.put("3", "value3")
//第一种:普遍使用,二次取值
System.out.println("通过Map.keySet遍历key和value:")
for (String key : map.keySet()) {
System.out.println("key= " key " and value= " map.get(key))
}
//第二种
System.out.println("通过Map.entrySet使用iterator遍历key和value:")
Iterator
while (it.hasNext()) {
Map.Entry
System.out.println("key= " entry.getKey() " and value= " entry.getValue())
}
//第三种:推荐,尤其是容量大时
System.out.println("通过Map.entrySet遍历key和value")
for (Map.Entry
System.out.println("key= " entry.getKey() " and value= " entry.getValue())
}
//第四种
System.out.println("通过Map.values()遍历所有的value,但不能遍历key")
for (String v : map.values()) {
System.out.println("value= " v)
}
}
当一个人找不到出路的时候,最好的办法就是将当前能做好的事情做到极致,做到无人能及。
如何在velocity遍历HashMap
#foreach ($member in $map.entrySet())
$!{n.subject}
$!{util.formatDate($n.createdTime)}
$member.key.catagoryName
#foreach ($n in $member.value)
#end
#end
如何使用javascript遍历map集合
可以使用jquery中的each()函数。
$.each(obj, function(i) {    
    alert(obj[i])    
})  
function 也可以写为function(key,value){
 }
key,value 就是map的key, value
如何遍历map
因为看不懂,你的里面的map是代表什么意思,我就直接贴代码
for (Iterator iter = paramers.entrySet().iterator() iter
.hasNext()) {
Map.Entry element = (Map.Entry) iter.next()
Object strKey = element.getKey()
String strObj = (String) element.getValue()
String vStrObj = strObj
}
怎么遍历显示list中存放的map集合
<%
List<Map> list = new ArrayList<Map>()
Map<String,String> map1 = new HashMap<String,String>()
map1.put("testaa","mytestaa")
map1.put("testbb","mytestbb")
Map<String,String> map2 = new HashMap<String,String>()
map2.put("testcc","mytestcc")
map2.put("testdd","mytestdd")
list.add(map1)
list.add(map2)
pageContext.setAttribute("list",list)
%>
假设使用jstl标签输出:
<c:forEach items="${list}" var="temp">
<c:forEach items="${temp}" var="map">
${map.key}---->${map.value}<br>
</c:forEach>
</c:forEach>