Another iterator then?


for(Iterator i = new ReverseIterator(things);
      i.hasNext(); )
{
  Thing t = (Thing)i.next();

  if((t.age() < 30) && !t.shipped())
    print(t.name());
}
How about this? We invent a new iterator type that walks backwards over the list. Everything else can stay the same.

Now, if we want to go forward we use the normal iterator that the iterator() method gives us. If we want to go backwards we use our ReverseIterator.

You can write one of these, from scratch, with test cases, in under five minutes. (In fact, you can write two. The naive one and the good one.)