import java.util.LinkedList;
import java.util.ListIterator;
public class ListTest1
{ public static void main(String[] args)
{ LinkedList staff = new LinkedList();
staff.addLast("Dick");
staff.addLast("Harry");
staff.addLast("Romeo");
staff.addLast("Tom");
// | in the comments indicates the iterator position
ListIterator iterator = staff.listIterator(); // |DHRS
iterator.next(); // D|HRS
iterator.next(); // DH|RS
// add more elements after second element
iterator.add("Juliet"); // DHJ|RS
iterator.add("Nina"); // DHJN|RS
iterator.next(); // DHJNR|S
// remove last traversed element
iterator.remove(); // DHJN|S
// print all elements
iterator = staff.listIterator();
while (iterator.hasNext())
System.out.println(iterator.next());
}
}