Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
hard

Recursive Removal from ArrayList

Mark
< Prev
Next >

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

[C, D, E]

B

[B, D, E]

C

[A, C, E]

D

[B, C, E]

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|