List Iterator


public interface ListIterator
{
  void add(Object o);

  boolean hasNext();
  boolean hasPrevious();

  Object next();
  int nextIndex();

  Object previous();
  int previousIndex();

  void remove();
  void set(Object o);
}
Here's a ListIterator. It's the bigger, "better", beefier Iterator. As its name suggests, this has extra "stuff" related to lists - a list being an indexable linear sequence.

Has anyone here actually used one?

I said I thought Iterator was designed on the hoof. Wait until you get a load of this. nextIndex return the index in the list of the element that the next call next to would return. add inserts an element before the element that would be returned by the next call to next. Calling previous immediately after calling next returns the same element. remove removes the element returned by the most recent call to next or previous.

My head hurts.

I said if Iterator came up at a code review, you'd sent it back. If this came up, well ...