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 JDK And JRE ?

What are the Differences Between Comparable and Comparator in Jav ...

What are the Differences Between a Checked and Unchecked Exceptio ...

What is the Difference Between an ArrayList and a LinkedList Data ...

What is the Main Benefit of IOC Principle in Java ?