- import java.util.*;
- public class MaoTest01 {
- public static void main(String[] args) throws ClassCastException{
- Map persons = new HashMap();
-
- persons.put("110", "JAVA");
- persons.put("111", "AVA");
- persons.put("120", "VA");
- persons.put("114", "A");
- Set keys = persons.keySet();
-
- Iterator it = keys.iterator();
- while(it.hasNext()){
- Object id = it.next();
-
- Object name = persons.get(it.next());
- //这里应该为id因为it.next()为Iterator的指针,每调用一次.next,
- //指针会向后移动一次,由于你前面已经调用了.next()所以只打印了两次
- System.out.println(id+"--->"+name);
- }
-
-
- }
- }
复制代码 |