Difference between Iterator vs ListIterator
Here we will learn about differences between iterator and list iterator.
Iterator and ListIterator java differ based on following parameters:
1. Traversal direction
Iterator allows to traverse the List, Set and Map in only forward direction. Iterator is unidirectional in nature.
ListIterator allows to traverse the List (remember only List) in both forward and backward direction. ListIterator is bidirectional.
Iterator has next() method, using which forward traversal is possible.
ListIterator has next() method for forward traversal and previous() method for backward traversal.
3. Collection implementations that can be traversed
Iterator can traverse List, Set and Map.
ListIterator can only be used for List traversal.
4. Modifying the elements while traversing
Iterator can only remove the element during iteration. It has only remove() method.
ListIterator can add, remove and set elements during iteration.
5. Current position
Iterator cannot determine the current position of iteration during iterating over List.
ListIterator can determine the current position of iteration during iterating over List.
6. Retrieve index
Index of the element cannot be retrieved using Iterator.
Index of the element can be retrieved using ListIterator using previousIndex() and nextIndex() method.
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Technology geek, loves to write and share knowledge with the world. Having 9+ years of IT experience. B.Tech in Computer Science & Engineering
Page Views :
Published Date :