previous | start | next

Implementing the Iterable<Key> keys() Method

The keys method has to return a reference to some object that has a method:

 Iterator<Key> iterator()      
   

The Iterator<Key> that this iterator() method returns should allow the keys to be returned, one at a time and in sorted order, using the next() method.

The Queue<E> class implements Iterable<E> [Queue has an Iterator<E> iterator() method].

So one implementation of keys() would be to



previous | start | next