android/guava/src/com/google/common/collect/Iterators.java
public static <T> Iterator<T> consumingIterator(final Iterator<T> iterator) {
    checkNotNull(iterator);
    return new UnmodifiableIterator<T>() {
      @Override
      public boolean hasNext() {
        return iterator.hasNext();
      }

      @Override
      public T next() {
        T next = iterator.next();
        iterator.remove();
        return next;
      }

      @Override
      public String toString() {
        return "Iterators.consumingIterator(...)";
      }
    };
  }
public static <T> Iterator<T> consumingIterator(final Iterator<T> iterator) {
    checkNotNull(iterator);
    return new UnmodifiableIterator<T>() {
      @Override
      public boolean hasNext() {
        return iterator.hasNext();
      }

      @Override
      public T next() {
        T next = iterator.next();
        iterator.remove();
        return next;
      }

      @Override
      public String toString() {
        return "Iterators.consumingIterator(...)";
      }
    };
  }
public static < T > Iterator < T > consumingIterator ( final Iterator < T > iterator ) { checkNotNull ( iterator ) ; return new UnmodifiableIterator < T > ( ) { @ Override public boolean hasNext ( ) { return iterator . hasNext ( ) ; } @ Override public T next ( ) { T next = iterator . next ( ) ; iterator . remove ( ) ; return next ; } @ Override public String toString ( ) { return "Iterators.consumingIterator(...)" ; } } ; }
Returns a view of the supplied {@code iterator} that removes each element from the supplied
{@code iterator} as it is returned.

<p>The provided iterator must support {@link Iterator#remove()} or else the returned iterator
will fail on the first call to {@code next}.

@param iterator the iterator to remove and return elements from
@return an iterator that removes and returns elements from the supplied iterator
@since 2.0
Returns a view of the supplied { @code iterator } that removes each element from the supplied { @code iterator } as it is returned .