LinkedList listIterator() Method in Java
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:
// Java code to illustrate listIterator() import java.io.*; 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 list.add("Geeks"); list.add("for"); list.add("Geeks"); list.add("10"); list.add("20"); // 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:"); while(list_Iter.hasNext()){ System.out.println(list_Iter.next()); } } } |
LinkedList:[Geeks, for, Geeks, 10, 20] The list is as follows: Geeks 10 20
Recommended Posts:
- CopyOnWriteArrayList listIterator() method in Java
- Stack listIterator() method in Java with Example
- Stack listIterator(int) method in Java with Example
- Vector listIterator() method in Java with Examples
- ArrayList listIterator() method in Java with Examples
- List listIterator() Method in Java with Examples
- AbstractList listIterator() Method in Java with Examples
- LinkedList set() Method in Java
- LinkedList get() Method in Java
- LinkedList pop() Method in Java
- LinkedList contains() Method in Java
- LinkedList add() Method in Java
- LinkedList getFirst() Method in Java
- LinkedList spliterator() method in Java
- LinkedList getLast() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



