如果我创建一个新对象,程序运行正常:
Iterator iter = Students.iterator();
while (iter.hasNext()){
Student newstudent=(Student) iter.next();
if (newstudent.getCourse()==2){
System.out.println( newstudent.getName());}
但如果不喜欢:
Iterator iter = Students.iterator();
while (iter.hasNext()){
if (((Student) iter.next()).getCourse()==2){
System.out.println(( (Student)iter.next()).getName());}//Here it is printing out the next object afther that I have checked
如何坚持同一个对象?