Map没有实现Iterator接口
要实现迭代就需要把它转换成Set集合,然后迭代- Map<String,String> map = new HashMap<String,String>();
- map.put("02", "zhangsan2");
- map.put("03", "zhangsan3");
- map.put("01", "zhangsan1");
- map.put("04", "zhangsan4");
-
- Set<Map.Entry<String,String>> entrySet = map.entrySet();
-
- Iterator<Map.Entry<String,String>> it = entrySet.iterator();
-
- while(it.hasNext())
- {
- Map.Entry<String,String> me = it.next();
- String key = me.getKey();
- String value = me.getValue();
- System.out.println("key:"+key+" value:"+value);
-
- }
复制代码 map迭代就是这么玩的 |