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
easy Solved by 1 students

While Loop Condition for List Modification

Mark
< Prev
Next >

The following code segment is intended to repeatedly remove the last element from the elements list until only one element remains. Which expression should replace /* missing condition */ for the code to work as intended?

List<Integer> elements = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
while (/* missing condition */) {
  elements.remove(elements.size() - 1);
}
A

elements.size() > 1

B

elements.isEmpty()

C

elements.get(0) != 1

D

elements.size() != 5

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|