Difference between Enumeration, Iterator, and ListIterator in Java

In the previous tutorial, we have learned about when and how to use, Enumeration, Iterator, and ListIterator cursor in Java but on this page, we are going to see the what are the similarities and difference between these.

Let’s see the comparison table for more details.

Properties Enumeration Iterator ListIterator
Applicable for Only Legacy classes Any Collection implemented classes Only List implemented classes
Movement Only forward direction Only forward direction Both forward and backward
Accessibility Only read access Read and remove access Read, remove, replace, and add access
How to get it? elements() method of Vector class iterator() method Collection interface listIterator() method List interface
Methods hasMoreElements() and nextElements() hasNext(), next(), remove(), and forEachRemaining(Consumer<? super E> action) hasNext(), next(), nextIndex(), hasPrevious(), previous(), previousIndex(), remove(), set(Object obj), and add(Object obj)
Is it legacy? Yes No No

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.