Here are 10 essential multiple-choice questions on Java Iterators, covering key concepts.
Question 3
What happens if next() is called on an Iterator when there are no more elements?
Question 6
What is the output of the following code?
import java.util.*;
public class Geeks {
public static void main(String[] args) {
List<String> list = new ArrayList<>(Arrays.asList("A", "B", "C"));
Iterator<String> iterator = list.iterator();
while(iterator.hasNext()) {
System.out.print(iterator.next() + " ");
iterator.remove();
}
System.out.println(list.isEmpty());
}
}
Question 9
Which exception occurs when an Iterator is used after modifying the collection directly?
There are 10 questions to complete.
Quiz about Java Iterators