Java LinkedList.listIterator(int index)

Syntax

LinkedList.listIterator(int index) has the following syntax.

public ListIterator <E> listIterator(int index)

Example

In the following code shows how to use LinkedList.listIterator(int index) method.


/*  w  ww  .jav  a2 s. co m*/
import java.util.Iterator;
import java.util.LinkedList;

public class Main {

   public static void main(String[] args) {

      // create a LinkedList
      LinkedList<String> list = new LinkedList<String>();

      // add some elements
      list.add("Hello");
      list.add("from java2s.com");
      list.add("10");

      // print the list
      System.out.println("LinkedList:" + list);

      // set Iterator at specified index
      Iterator x = list.listIterator(1);

      // print list with the iterator
      while (x.hasNext()) {
         System.out.println(x.next());
      }
   }
}

The code above generates the following result.