Difficulty: Easy
Correct Answer: 1, 3, 4 and 5
Explanation:
Introduction / Context:
Java provides Iterator
for one-way traversal and ListIterator
for bidirectional traversal and in-place modification of lists. This question checks which capabilities belong to which interface.
Given Data / Assumptions:
Iterator
, inheritance relationships, and features of ListIterator
.
Concept / Approach:
Iterator
declares exactly three methods: hasNext()
, next()
, and remove()
. ListIterator
extends Iterator
(not List
) and adds backward traversal (hasPrevious()
, previous()
), modification methods (add()
, set()
, and remove()
inherited), and positional queries (nextIndex()
, previousIndex()
).
Step-by-Step Solution:
Verification / Alternative check:
The Javadoc for java.util.ListIterator
lists these additional methods explicitly and shows it extends Iterator
.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing List
(a collection type) with ListIterator
(an iterator over lists), and forgetting the backward traversal capability.
Final Answer:
1, 3, 4 and 5
Discussion & Comments