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|
- Core Java Interview Questions and Answers Part 3
- How to get free, usable, and total disk space in Java
- Find first repeated character in a string using Java
- How to insert line number in file using Java
- How to set Thread priority in Java