ListIterator, maybe?


for(ListIterator i =
          things.listIterator(things.size());
      i.hasPrevious(); )
{
  Thing t = (Thing)i.previous();

  if((t.age() < 30) && !t.shipped())
    print(t.name());
}
So here we are, using a list iterator. It's not a drop-in change. It's so odd looking it'll give most people pause.

Basically, ListIterator is so tortured that almost no one used. I had a sniff about using Google Codesearch. Aside from 3rd party Java implementations, I only found a handful of places it was used, and nearly all of those actually only used it like an normal Iterator. I didn't find any cases where anyone goes forward then back and then forward again.

What if we need to be able to switch at runtime? Sometimes we want the list in its natural order, sometimes we want it in reverse. It's not unreasonable is it? Or is it?

Have we hit the limit of a Java iterator?