This method returns a list iterator over the elements in the mentioned list (in proper sequence), starting at the specified position in the list.
ListIterator listIterator(int index)
Parameters: This method has only argument, i.e, index – index of the first element to be returned from the list iterator (by a call to next).
Returns: This method returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
Exception: This method throws an exception IndexOutOfBoundsException – if the index is out of range (index size())
Below programs show the implementation of this method.
ArrayList: [1, 3, 6, 9] Using ListIterator: Value is : 1 Value is : 3 Value is : 6 Value is : 9
Program 2: Below is the code to show implementation of list.subList() using Linkedlist.
ArrayList: [A, B, C, D] Using ListIterator: Value is : A Value is : B Value is : C Value is : D
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.