01: import java.util.LinkedList;
02: import java.util.ListIterator;
03: 
04: /**
05:    A program that demonstrates the LinkedList class
06: */
07: public class ListTester
08: {  
09:    public static void main(String[] args)
10:    {  
11:       LinkedList<String> staff = new LinkedList<String>();
12:       staff.addLast("Dick");
13:       staff.addLast("Harry");
14:       staff.addLast("Romeo");
15:       staff.addLast("Tom");
16:       
17:       // | in the comments indicates the iterator position
18: 
19:       ListIterator<String> iterator 
20:             = staff.listIterator(); // |DHRT
21:       iterator.next(); // D|HRT
22:       iterator.next(); // DH|RT
23: 
24:       // Add more elements after second element
25:       
26:       iterator.add("Juliet"); // DHJ|RT
27:       iterator.add("Nina"); // DHJN|RT
28: 
29:       iterator.next(); // DHJNR|T
30: 
31:       // Remove last traversed element 
32: 
33:       iterator.remove(); // DHJN|T
34:      
35:       // Print all elements
36: 
37:       for (String name : staff)
38:          System.out.println(name);
39:    }
40: }