Map<Integer, String> temp = new HashMap<Integer, String>();
for (int i = 0; i < 10; i++) {
String str = "string" + i;
temp.put(new Integer(i), str);
}
if (temp.containsKey(new Integer(5))) {// 判断键是否重复
System.out.println("Contains!");
} else {
System.out.println("No contains!");
}
for (Iterator it = temp.entrySet().iterator(); it.hasNext();) {
Map.Entry e = (Map.Entry) it.next();
System.out.print("key: " + e.getKey());
System.out.println(" value: " + e.getValue());
}
关于HashMap的存值和迭代.