Java Reference
In-Depth Information
Next, let us turn to the iterator class. The ListIterator interface in the standard
library defines nine methods. We omit four of them (the methods that move the
iterator backwards and the methods that report an integer index of the iterator).
Figure 5
Removing the First Node from a Linked List
Our LinkedList class defines a private inner class LinkedListIterator ,
which implements the simplified ListIterator interface. Because
LinkedListIterator is an inner class, it has access to the private features of the
LinkedList classȌin particular, the first field and the private Node class.
Note that clients of the LinkedList class don't actually know the name of the
iterator class. They only know it is a class that implements the ListIterator
public class LinkedList
. . .
public ListIterator listIterator()
return new LinkedListIterator();
private class LinkedListIterator
implements ListIterator
public LinkedListIterator()
position = null;
previous = null;
. . .
Search WWH ::

Custom Search