I want to make a look up for entry in ArrayList and remove element if it's found, the simplest way I guess is through Iterator, here's my code:
for (Iterator<Student> it = school.iterator(); it.hasNext();){
if (it.equals(studentToCompare)){
it.remove();
return true;
}
System.out.println(it.toString());
it.next();
}
But something is wrong: instead of iterating through my ArrayList<Student> school I get using it.toString():
java.util.ArrayList$Itr@188e490
java.util.ArrayList$Itr@188e490
...
What's wrong?
Listhas.remove()!!toString()of the iterator, not ofStudentArrayList$Itr@188e490is the address of the iterator itself.