Collection c2 =new ArrayList();
Student s= new Student();
c2.add(s);
c2.add("我");
Iterator it = c2.iterator();
while (it.hasNext()) {
it.next();
Object object = (Object) it.next();
System.out.println(object);
}
输出结果为“我”,并没有s对象啊?
阿神2017-04-18 10:50:25
while (it.hasNext()) {
it.next(); //第一个对象 Student
Object object = (Object) it.next(); //第二个对象 String
System.out.println(object);
}
while循环里一次next了两次