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 ArrayList

Mark
< Prev
Next >

The following code segment is intended to remove elements from the elements list until only one element remains. Which condition should replace /* missing condition */ for the code to function 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() != 5

B

elements.isEmpty()

C

elements.size() > 1

D

elements.get(0) != 1

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|