Safely remove all elements equal to 0:
- A
for (int i = list.size() - 1; i >= 0; i--) if (list.get(i) == 0) list.remove(i);
- B
for-each with remove
- Ccheck_circle
Both work; second avoids index shifting issues
- D
for (int i = 0; i < list.size(); i++) if (list.get(i) == 0) list.remove(i);
Explanation
Iterating backwards avoids skipping after removal.