2015-11-28 15:23
最佳答案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import
java.util.HashMap;
import
java.util.Map;
public
class
Demo {
public
static
void
main(String[] args) {
Map<Integer,Integer> m =
new
HashMap<Integer,Integer>();
m.put(
1
,
1
);
print(m);
m.put(
1
,
2
);
print(m);
}
private
static
void
print(Map<Integer, Integer> m) {
for
(Map.Entry<Integer, Integer> mm : m.entrySet())
System.out.println(
"K: "
+mm.getKey()+
",V: "
+mm.getValue());
}
}
//供参考,重新放一个相同的key,会自动覆盖value的。
|