1.先将map对象转成set,然后再转为迭代器
1 Iterator iterator = map.entrySet().iterator(); 2 while(iterator.hasNext()){ 3 Entry entry = iterator.next(); 4 System.out.println(entry.getKey()); // 获取key 5 System.out.println(entry.getValue()); // 获取value 6 }
2.先将map转为set类型的key值集合,然后转为迭代器
1 Iterator iterator = map.keySet().iterator(); 2 while(iterator.hasNext()){ 3 Object key = (Object)iterator.next(); 4 System.out.println(key); // 获取key 5 System.out.println(map.get(key)); // 获取value 6 }