| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
hard Solved by 1 students
Recursive ArrayList Element Removal
< Prev
Next >

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]

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.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy