Difference between Enumeration, Iterator, and ListIterator in Java
In the previous tutorial, we have learned about when and how to use,
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.
|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|
- Java method overloading and overriding example
- Core Java Interview Questions and Answers Part 3
- How to get file extension in Java
- Java 8- How to replace word in a File using Stream
- How to shuffle list elements in Java