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.

PropertiesEnumerationIteratorListIterator
Applicable forOnly Legacy classesAny Collection implemented classesOnly List implemented classes
MovementOnly forward directionOnly forward directionBoth forward and backward
AccessibilityOnly read accessRead and remove accessRead, remove, replace, and add access
How to get it?elements() method of Vector classiterator() method Collection interfacelistIterator() method List interface
MethodshasMoreElements() 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?YesNoNo

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.