Recursive Removal from ArrayList
What is printed as a result of executing the following code?
import java.util.*;
public class Main {
public static void recursiveRemove(ArrayList<String> list, int index) {
if (index >= list.size()) {
return;
}
if (index % 2 == 0) {
list.remove(index);
}
recursiveRemove(list, index + 1);
}
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>(Arrays.asList("A", "B", "C", "D", "E"));
recursiveRemove(list, 0);
System.out.println(list);
}
}
A
[A, C, E]
B
[B, C, E]
C
[C, D, E]
D
[B, D, E]
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE