Articles

Difference between Iterator vs ListIterator

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.
2. Method
  • 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.

 

 


Java Interview Questions

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Rohanjit Kumar
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 : Jun 28,2020  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!