While Loop Condition for ArrayList
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
Question Leaderboard
Not enough data yet to show leaderboard.
