code: public <E extends T> Iterator<E> filter (final Iterator<E> input)
      {
          return new Iterator<E>() {
              // from Iterator
              public boolean hasNext ()
              {
                  return _found || findNext();
              }
  
              // from Iterator
              public E next ()
              {
                  if (_found || findNext()) {
                      _found = false;
                      return _last;
  
                  } else {
                      throw new NoSuchElementException();
                  }
              }
  
              // from Iterator
              public void remove ()
              {
                  if (_removeable) {
                      _removeable = false;
                      input.remove();
  
                  } else {
                      throw new IllegalStateException();
                  }
              }
  
              private boolean findNext ()
              {
                  boolean result = false;
                  while (input.hasNext()) {
                      E candidate = input.next();
                      if (isMatch(candidate)) {
                          _last = candidate;
                          result = true;
                          break;
                      }
                  }
  
                  _found = result;
                  _removeable = result;
                  return result;
              }
  
              private E _last;
              private boolean _found; // because _last == null is a valid element
              private boolean _removeable;
          };
      }
docs: Return a new iterator that contains only matching elements from
  the input iterator.