Multiple choice technology programming languages

What is an Iterator ?

  1. Enables you to cycle through a collection in the forward direction only, for obtaining or removing elements

  2. just for loop

  3. while loop

  4. It is an class for storing objects

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

An Iterator in Java provides a uniform way to access elements of a collection sequentially, allowing both retrieval and removal of elements during iteration. It differs from simple loops (options B, C) which are control flow constructs, not a dedicated interface for traversing collections. Option D incorrectly describes it as a storage class rather than an access mechanism.

AI explanation

An Iterator is an object designed to traverse a collection one element at a time, moving only forward, and it exposes methods to retrieve or remove the current element as you go. It's not itself a loop construct (like for or while) or a storage container — it's the mechanism that lets you walk through whatever collection it's bound to, regardless of the collection's internal structure.