Returns a view of the supplied iterator that removes each element from the supplied iterator as it is returned. The provided iterator must support Iterator#remove() or else the returned iterator will fail on the first call to next. @param iterator the iterator to
(final Iterator<T> iterator)
| 975 | |
| 976 | |
| 977 | public static <T> Iterator<T> consumingIterator(final Iterator<T> iterator) { |
| 978 | checkNotNull(iterator); |
| 979 | return new UnmodifiableIterator<T>() { |
| 980 | @Override |
| 981 | public boolean hasNext() { |
| 982 | return iterator.hasNext(); |
| 983 | } |
| 984 | |
| 985 | @Override |
| 986 | public T next() { |
| 987 | T next = iterator.next(); |
| 988 | iterator.remove(); |
| 989 | return next; |
| 990 | } |
| 991 | |
| 992 | @Override |
| 993 | public String toString() { |
| 994 | return "Iterators.consumingIterator(...)"; |
| 995 | } |
| 996 | }; |
| 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * Deletes and returns the next value from the iterator, or returns |