Skip to content
Sharp

Collections · interview question

Why can using an enhanced for loop over an iterator when traversing a collection become a problem in production code?

Multiple choiceMediumchapter-4-curatedpremiumcollectionsiteration-and-traversal
Choose one answer
Answer and explanation

Correct answer

C. Cannot modify collection structure

Why

The enhanced for loop does not allow modifications to the collection's structure, such as removing elements, without causing a ConcurrentModificationException.

Test yourself on Collections

A free test with instant, explained results. No account needed.

Start free test
All Collections questions →