I would like to remove an element from an ArrayList
in Java if it meets a certain criteria.
ie:
for (Pulse p : pulseArray) {
if (p.getCurrent() == null) {
pulseArray.remove(p);
}
}
I can understand why this does not work, but what is a good way to do this?
When you are removing the element from the same list, the index gets disturbed. Try little differently as below: