Advertisement



< Prev
Next >




Difference between Iterator and ListIterator






We know that we can cycle over the elements of collection classes using methods of Iterator and ListIterator. But let's discuss the difference between the two.

Important differences between Iterator and ListIterator


ListIterator Iterator
ListIterator works only in the collection classes that has implemented List interface such as ArrayList, LinkedList etc. Iterator can be used to cycle over elements of any collection class such as ArrayList, LinkedHashSet, PriorityQueue etc
ListIterator allows a bidirectional access of a list, i.e. accessing a list in the forward or backward direction Iterator only allows a forward access of a collection.
ListIterator also provide support to modify the elements while iterating them. Iterator does not allow modification of elements while iterating them.
ListIterator allows us to add new elements to the list. Iterator does not allow us to add new elements to a collection.
ListIterator extends Iterator and hence it is a subclass of Iterator. Iterator is a superclass of ListIterator.



Please share this article -





< Prev
Next >
< listIterator() to iterate
Maps >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement