- package cn.itcast_1;
- import java.util.HashMap;
- import java.util.Set;
- public class HashMapDemo {
- public static void main(String[] args) {
- //创建集合对象
- HashMap<Integer, String> hm = new HashMap<Integer,String>();
- //创建元素和添加
- hm.put(004, "aaa");
- hm.put(005, "sss");
- hm.put(006, "ddd");
- hm.put(007, "fff");
- hm.put(008, "ggg");
- //获取键,根据键找到值。遍历
- Set<Integer> set =hm.keySet();
- for(Integer key:set){
- String value =hm.get(key);
- System.out.println(key+"..."+value);
- }
-
- }
- }
复制代码
为什么会报错呢?
|
|