The problem is you are calling it.next()
twice, which will advance the iterator two times.
You should store the value to avoid repeating the side-effect.
Person person = it.next();
if (tmp.getLastDiscovered() == person.getLastDiscovered()) {
getHelper().delete(tmp);
}
tmp = person;
Alternatively, you could use the for-each loop to avoid needing to interact with the iterators (I assume all Person
are not null):
Person tmp = null;
for (Person person : persons) {
if (tmp != null && tmp.getLastDiscovered() == person.getLastDiscovered()) {
getHelper().delete(tmp);
}
tmp = person;
}