1.

Iterator vs ListIterator in Java

Answer»

Both ITERATOR and ListIterator in Java are an interface in the Collection framework. The Iterator is used to traverse the Collection elements by iterating each element individually in the forward direction.

ListIterator extends the Iterator and is used to traverse the Collection elements in both forward and BACKWARD directions. Also, elements can be added, modified and removed in the Collection using ListIterator which is not possible using Iterator.

The differences between Iterator and ListIterator are given as FOLLOWS:

Iterator
ListIterator
The Iterator is used to traverse the Collection elements in the forward direction.
The ListIterator is used to traverse the Collection elements in the forward and backward direction.
Maps, Lists, SETS etc. can be traversed using an Iterator.
Only List objects can be traversed using a ListIterator.
Elements cannot be modified in a Collection by an Iterator.
Elements can be modified in a Collection by a ListIterator.
Elements cannot be added to a Collection by an Iterator.
Elements can be added to a Collection by a ListIterator.
There is no METHOD in the Iterator to find an element index in a Collection.
There is a method in the ListIterator to find an element index in a Collection.


Discussion

No Comment Found