根据JDK5的新特性,用For循环Map,例如循环Map的Key
1
2
3
|
for
(String dataKey : paraMap.keySet()) {
System.out.println(dataKey );
}
|
循环整个map的key和value
1
2
3
4
5
6
7
8
9
10
11
12
|
Map<Integer,String> map =
new
HashMap<Integer,String>();
map.put(
1
,
"A"
);
map.put(
2
,
"B"
);
map.put(
3
,
"C"
);
map.put(
4
,
"D"
);
map.put(
5
,
"E"
);
map.put(
6
,
"F"
);
map.put(
7
,
"G"
);
for
(Map.Entry<Integer, String> entry: map.entrySet()) {
System.out.print(entry.getKey() +
":"
+ entry.getValue() +
"\t"
);
}
|