...

/

ArrayList: Iteration using ListIterator

ArrayList: Iteration using ListIterator

Let's discuss how to iterate an ArrayList using a ListIterator.

ListIterator

The Iterator provides very limited capabilities as we can iterate only in the forward direction and we can’t update or insert an element to the list while iterating. To overcome these problems, we can use ListIterator. The listIterator() method returns an object of type ListIterator which can then be used to iterate the ArrayList.

Below are the methods that are available in the ListIterator interface.

  1. hasNext() — This method is used to check if there is a next element in the list when the list is iterated in the forward ...