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