ArrayList<Integer> list = new ArrayList<>();
list.add(2); list.add(2); list.add(3); list.add(4);
for (int i = 0; i < list.size(); i++) {
if (list.get(i) == 2) {
list.remove(i);
}
}What does list contain?
- A
[]
- B
[3, 4]
- C
[2, 2, 3, 4]
- Dcheck_circle
[2, 3, 4]
Explanation
After removing index 0, the second 2 shifts to index 0 but i becomes 1, skipping it.