You have seen the iteration of elements in the following examples earlier.
Also you have seen the analogy of Enumeration vs Iterator.
Differences between Enumeration, Iterator and ListIterator are very confusing for a Beginner. Understandability increases when placed at a single place. Towards this effort, let us summarize the differences Iterator vs ListIterator.
Table of differences between Iterator and ListIterator and extra features with ListIterator.
|Can do remove operation only on elements||Can remove, add and replace elements|
|Method is remove()||Methods are remove(), add() and set()|
|iterator() method returns an object of Itertor||listIterator() method returns an object of ListItertor|
|iterator() method is available for all collections. That is, Iterator can be used for all collection classes||listIterator() method is available for those collections that implement List interface. That is, descendants of List interface only can use ListIterator|
Table: Iterator vs ListIterator
Both are interfaces introduced with JDK 1.2 only. Both comes with the same methods of iteration and retrieval – hasNext() and next(). Both iterators are fail-fast.
Pass your comments and suggestions to improve the quality of this tutorial "Iterator vs ListIterator"