ListIterator extends the Iterator interface to support bidirectional iteration of lists. : List « Utility Classes « SCJP






import java.util.LinkedList;
import java.util.ListIterator;
   
public class MainClass {
 public static void main(String args[]){
    LinkedList list = new LinkedList();
    list.add("is");
    list.add("is");
    list.add("a");
    list.add("a");
    list.add(null);
    list.addLast("test");
    list.addFirst("This");
    displayList(list);
 }
 static void displayList(LinkedList list) {
  System.out.println("The size of the list is: "+list.size());
  ListIterator i = list.listIterator(0);
  while(i.hasNext()){
   Object o = i.next();
   if(o == null) System.out.println("null");
   else System.out.println(o.toString());
  }
 }
}
The size of the list is: 7
This
is
is
a
a
null
test








8.13.List
8.13.1.A List keeps it elements in the order in which they were added.
8.13.2.List: void add(int index, Object x) Inserts x at index.
8.13.3.List: Object get(int index) Returns the element at index.
8.13.4.List: int indexOf(Object x) Returns the index of the first occurrence of x, or -1 if the List does not contain x.
8.13.5.Collection: Object remove(int index) Removes the element at index.
8.13.6.ListIterator extends the Iterator interface to support bidirectional iteration of lists.
8.13.7.Using Iterator for Lists
8.13.8.toArray() method