Skip to content

Instantly share code, notes, and snippets.

@andras-gyarmati
Last active January 23, 2018 23:37
Show Gist options
  • Select an option

  • Save andras-gyarmati/886fdb3188cd7e5b32625a8b5e64e243 to your computer and use it in GitHub Desktop.

Select an option

Save andras-gyarmati/886fdb3188cd7e5b32625a8b5e64e243 to your computer and use it in GitHub Desktop.
processing remove items from arraylist while iterating
void foo() {
if (list.size() > 0) {
boolean finished = false;
int i = 0;
Bar b;
while (!finished) {
b = list.get(i);
if (b.condition == whatever) {
list.remove(b);
} else {
i++;
}
if (i >= list.size()) {
finished = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment