AbstractSequentialList listIterator(): method in Java is used to get a listIterator over this list. It returns a list iterator over the elements in this list (in proper sequence).
public abstract ListIterator listIterator(int index)
Parameters: This method takes a parameter index which is the index of first element to be returned from the list iterator (by a call to the next method)
Returns: This method returns a list iterator over the elements in this list (in proper sequence).
Exceptions: This method throws IndexOutOfBoundsException, if the index is out of range (index size())
Below is the code to illustrate ListIterator():
6 7 10 8 7
Program 2: To demonstrate IndexOutOfBoundException
[5, 9, 6, 7, 10, 8, 7] Exception: java.lang.IndexOutOfBoundsException: Index: 15, Size: 7
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.