A bit more filtering
for(Iterator i = things.iterator(); i.hasNext(); )
{
Thing t = (Thing)i.next();
if((t.age() < 30) && !t.shipped())
print(t.name());
}
There you go. Less than 30 days old, not shipped, bish-bosh, there you go.
And he says, "can I have them in reverse order?"
And we say "erm ..."
What are my options?
Can't reverse the collection, because I need it elsewhere in the right order. Well, I could reverse it, and then reverse it again, but nasty.
Copy/clone, then reverse. Could do. But what if my list is large? That could be expensive.
So we think a bit, and perhaps we remember ListIterator. ListIterators can go forward and backwards. We could ask for it to be positioned at the end of the list, then work towards the front.