What is the Difference Between an Iterator and ListIterator in Java ?

Iterator and ListIterator are two interfaces in Java to traverse data structures. The differences between these two are...

ListIterator can be used to traverse only a List. But Iterator can be used to traverse List, Set, and Queue etc.

An Iterator traverses the elements in one direction only. It just goes. ListIterator can traverse the elements in two directions i.e. backward as well as forward directions.

Iterator cannot provide us index of an element in the Data Structure. ListIterator provides us methods like nextIndex() and previousIndex() to get the index of an element during traversal.

Iterator does not allow us to add an element to collection while traversing it. It throws ConcurrentModificationException. ListIterator allows use to add an element at any point of time while traversing a list.

An existing element’s value cannot be replaced by using Iterator. ListIterator provides the method set(e) to replace the value of last element returned by next() or previous() methods.



You May Interest

What is the Difference Between Sleep and Wait Methods in Java ?

What are the Advantages of Multithreading in Java ?

How Will You Handle InterruptedException in Java ?

Can We Use Thread.sleep Method For Real-time Processing in Java ?

What are the Differences Between a Vector and an ArrayList in Jav ...