![]() |
VOOZH | about |
In Java, the listIterator() method of theLinkedList class returns a ListIterator that allows us to iterate over the elements of the list.
Example:
Geeks For Geeks
Now there are two versions of listIterator() method i.e. without index and with an index.
It creates an ListIterator that starts form the beginning of the list.
Syntax:
public ListIterator<E> listIterator()
Return type: It returns a ListIterator that starts from the beginning of the list.
Example: Here, we use listIterator() to iterate over the elements of the list.
Traversing the List from index 0: A B C D E
The listIterator(int index) method creates a ListIterator that starts iterating from the specified index in the list.
Syntax:
ListIterator<E> listIterator(int index);
Example: Here, we use the listIterator() method to iterate over the elements of the list from the specified index.
Traversing the List forward from index 3: 400 500 600 700