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.
Syntax:
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:
import java.io.*;
import java.util.LinkedList;
import java.util.ListIterator;
public class LinkedListDemo {
public static void main(String args[])
{
LinkedList<String> list = new LinkedList<String>();
list.add( "Geeks" );
list.add( "for" );
list.add( "Geeks" );
list.add( "10" );
list.add( "20" );
System.out.println( "LinkedList:" + list);
ListIterator list_Iter = list.listIterator( 2 );
System.out.println( "The list is as follows:" );
while (list_Iter.hasNext()){
System.out.println(list_Iter.next());
}
}
}
|
Output:
LinkedList:[Geeks, for, Geeks, 10, 20]
The list is as follows:
Geeks
10
20