Java Programming - Objects and Collections - Discussion


Which of the following are true statements?

  1. The Iterator interface declares only three methods: hasNext, next and remove.
  2. The ListIterator interface extends both the List and Iterator interfaces.
  3. The ListIterator interface provides forward and backward iteration capabilities.
  4. The ListIterator interface provides the ability to modify the List during iteration.
  5. The ListIterator interface provides the ability to determine its position in the List.

[A]. 2, 3, 4 and 5
[B]. 1, 3, 4 and 5
[C]. 3, 4 and 5
[D]. 1, 2 and 3

Answer: Option B


The ListIterator interface extends the Iterator interface and declares additional methods to provide forward and backward iteration capabilities, List modification capabilities, and the ability to determine the position of the iterator in the List.

Bryan Pack said: (Apr 28, 2016)  
The answer could be either 'B' OR 'C' depending on the version of Java.

Iterator now has:

default void for EachRemaining(Consumer<? super E> action) in addition to boolean hasNext(), E next() & default void remove().

Ford Prefect said: (Jul 17, 2016)  
It's 2016, Java 7 is EOL already, so the Iterator interface has four methods, therefore C is correct, not B.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.