1Z0-829 Working with Arrays and Collections Practice Question
A developer needs to iterate over an ArrayList of integers and remove all elements that are less than 10. Which approach is best to avoid ConcurrentModificationException?
⚠ Common exam trap
Many candidates choose the Iterator approach (Option B) because they know it avoids ConcurrentModificationException, but they overlook that `removeIf()` is the more modern, concise, and recommended method for such bulk removal operations in Java.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use list.removeIf() with a lambda expression.
`list.removeIf()` is a built-in method introduced in Java 8 that safely removes elements from a collection based on a predicate, handling all iteration and modification internally without throwing ConcurrentModificationException. It uses an internal iterator that properly coordinates structural modifications, making it the most concise and reliable approach for this task.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use a for loop with index and list.remove(index) decrementing index.
Why it's wrong here
Works but error-prone; requires careful index handling.
- ✗
Use an Iterator with iterator.remove().
Why it's wrong here
Works but is not the best approach; removeIf is more concise.
- ✗
Use a for-each loop with list.remove().
Why it's wrong here
Using for-each with list.remove() throws ConcurrentModificationException.
- ✓
Use list.removeIf() with a lambda expression.
Why this is correct
removeIf is the cleanest and safest way; it uses an internal iterator and avoids ConcurrentModificationException.
Go deeper
Related to this question
About these practice questions
This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.