A singleton iterator

public class SingletonIterator implements Iterator
{
  public SingletonIterator(Object o) { o_ = o; }

  public boolean hasNext() {
    return (o_ != null);
  }

  public Object next() {
    if(o_ == null)
      throw new NoSuchElementException();
    Object o = o_;
    o_ = null;
    return o;
  }

  public void remove() { ... }

  private Object o_;
}
By singleton here, I mean a single object, not a "Singleton" global variable in disguise.

I suppose we could have used this in place of the NullIterator if we'd wanted.