A filtering iterator

public class FilterIterator implements Iterator
{
  public FilterIterator(Iterator iterator, Predicate predicate) ...

  public boolean hasNext()   {
    next_ = null;
    while(iter_.hasNext() && next_ == null)
    {
      Object candidate = iter_.next();
      if(pred_.text(candidate))
        next_ = candidate;
    }
    return next_ != null;
  }

  public Object next() { return next_; }

  public void remove() { iter_.remove(); }

  ...
}
Apologies for the formatting here. There's a trade off between legibility and readability on a slide like this.

Does this make sense?

Does this seem useful?

We could spend a lot of time writing little classes, anonymous or named, and that's great. The Predicate, here in this iterator, or in removeIf or whatever other methods are another extension point, another opportunity for flexibility. Along with our selection of iterators, our library of algorithms, we can also build a collection of Predicates.