Java用For循环Map
根据JDK的新特性,用For循环Map,例如循环Map的Key for(String dataKey : paraMap.keySet()){
System.out.println(dataKey );
}这里要注意的是,paraMap是怎么样定义的,如果是简单的Map paraMap = new HashMap();那前面的String就只能换成Object了.
对整Map的key和value都进行循环,如下:for(Map.Entry<String, Object> entry : paraMap.entrySet())
{
System.out.println(entry.getKey()+": "+entry.getValue());
}要是在以前,则是这么循环的:Iterator it = paraMap.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pairs = (Map.Entry)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
}from:http://go.cxweb.com.cn/y9z4r
页:
[1]