1.

What is the difference between Iterator and ListIterator?

Answer»

We can traverse the elements in a LIST using Iterator in a forward direction. Using LISTITERATOR, we can traverse the elements in the forward and backward direction both. Iterator can be USED in these collection types: List, Set, and Queue.

ListIterator can be used in List collection only.

Iterator has the following FUNCTIONALITIES:

  • boolean hasNext()
  • E next()
  • void remove()

ListIterator has the following functionalities:

  • void add (E e)
  • boolean hasNext()
  • boolean hasPrevious()
  • void remove()

Iterator can only perform remove operation while traversing the elements in a collection. If we TRY to add elements, it will throw ConcurrentModificationException.

ListIterator can perform add, remove operation while traversing the elements in a collection. We won’t get any exception while adding element using ListIterator.



Discussion

No Comment Found