Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Data Collections
Start Practice TestPractice Test
About Exam
medium

ArrayList Removal During Iteration

Mark
< Prev
Next >

Consider the following removeEvens method, which is intended to remove all even numbers from an ArrayList of integers.

public static void removeEvens(ArrayList<Integer> numbers) {
    for (int i = 0; i < numbers.size(); i++) {
        if (numbers.get(i) % 2 == 0) {
            numbers.remove(i);
        }
    }
}

If an ArrayList initially contains the elements [2, 4, 6, 8, 10], what will its contents be after a call to removeEvens?

A

[2, 4, 6, 8, 10]

B

[]

C

[6, 10]

D

[4, 8]

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: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|