根据JDK5的新特性,用For循环Map,例如循环Map的Key
Map<String, String> requestMap
for(String dataKey : requestMap.keySet()) {
System.out.print(dataKey +":");
System.out.println(requestMap.get(dataKey) );
}循环输出Key和Value。
注意的是,paraMap 是怎么样定义的,如果是简单的Map paraMap = new HashMap ();那前面的String就只能换成Object了.
整個map的key和value,
Map<Integer,String> map = new LinkedHashMap<Integer,String>();map.put(1, "星期一");map.put(2, "星期二");map.put(3, "星期三");map.put(4, "星期四");map.put(5, "星期五");map.put(6, "星期六");map.put(7, "星期日");for(Map.Entry<Integer, String> entry: map.entrySet()) { System.out.print(entry.getKey() + ":" + entry.getValue() + "\t");}
輸出:
1:星期一 2:星期二 3:星期三 4:星期四 5:星期五 6:星期六 7:星期日
本文出自 “羽鸿出品” 博客,请务必保留此出处http://5fresh.blog.51cto.com/5472694/1533201
原文地址:http://5fresh.blog.51cto.com/5472694/1533201