VOOZH about

URL: https://www.geeksforgeeks.org/java/vector-listiterator-method-in-java-with-examples/

⇱ Vector listIterator() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Vector listIterator() method in Java with Examples

Last Updated : 11 Jul, 2025
This method returns a list iterator over the elements of a Vector object in proper sequence. It is bidirectional, so both forward and backward traversal is possible, using next() and previous() respectively. The iterator thus returned is fail-fast. This means that structurally modifying the vector after the iterator is created, in any way except through the iterator's own remove or add methods (using Vector.add(), for example), will cause iterator to throw ConcurrentModificationException. Syntax:
public ListIterator listIterator()
Parameters: This method accepts no input arguments. Return Value: This method returns a ListIterator object which can be used to traverse the Vector object. Example 1: To demonstrate forward and backward traversal using listIterator().
Output:
Forward Traversal:
Geeks
for
Geeks
2019
AComputerSciencePortalForGeeks

Backward Traversal:
AComputerSciencePortalForGeeks
2019
Geeks
for
Geeks
This method is used to return a list iterator by specifying starting index. Also bidirectional and fail-fast. Syntax:
public ListIterator listIterator(int index)
Parameters: The parameter index is an integer type value that specifies the first element to be returned from the list iterator (by a call to next()). Return Value: This method returns a ListIterator object which can be used to traverse the Vector object. Exception: This method throws IndexOutOfBoundsException, if the index is out of range (index < 0 or index > size()) Example 2: To demonstrate listIterator(int index).
Output:
for
Geeks
Example 3: To demonstrate IndexOutOfBoundsException thrown by listIterator(int index).
Output:
Exception: java.lang.IndexOutOfBoundsException: Index: 5
Example 4: To demonstrate ConcurrentModificationException thrown by ListIterator object when Vector object is modified after creating list iterator to it.
Output:
Exception: java.util.ConcurrentModificationException
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Vector.html#listIterator--
Comment