Skip to content
Related Articles

Related Articles

Improve Article

LinkedList listIterator() Method in Java

  • Last Updated : 10 Dec, 2018

The Java.util.LinkedList.listIterator() method is used to return a list-iterator containing the same elements as that of the LinkedList in proper and same sequence starting from a specific position or index number which is passed as a parameter to this method.


ListIterator new_list = LinkedList.listIterator(int index);

Parameters: The parameter index is an integer type value that specifies the position of the element from where ListIterator starts operating and returning values.

Return Value: The method returns the list created using ListIterator, starting from the specified index.

Below program illustrate the Java.util.LinkedList.listIterator() method:

// Java code to illustrate listIterator()
import java.util.LinkedList;
import java.util.ListIterator;
public class LinkedListDemo {
    public static void main(String args[])
        // Creating an empty LinkedList
        LinkedList<String> list = new LinkedList<String>();
        // Use add() method to add elements in the list
        // Displaying the linkedlist
        System.out.println("LinkedList:" + list);
        // Setting the ListIterator at a specified position
        ListIterator list_Iter = list.listIterator(2);
        // Iterating through the created list from the position
        System.out.println("The list is as follows:");
LinkedList:[Geeks, for, Geeks, 10, 20]
The list is as follows:

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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :