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)
| 974 | |
| 975 | |
| 976 | public static <T> Iterator<T> consumingIterator(final Iterator<T> iterator) { |
| 977 | checkNotNull(iterator); |
| 978 | return new UnmodifiableIterator<T>() { |
| 979 | @Override |
| 980 | public boolean hasNext() { |
| 981 | return iterator.hasNext(); |
| 982 | } |
| 983 | |
| 984 | @Override |
| 985 | public T next() { |
| 986 | T next = iterator.next(); |
| 987 | iterator.remove(); |
| 988 | return next; |
| 989 | } |
| 990 | |
| 991 | @Override |
| 992 | public String toString() { |
| 993 | return "Iterators.consumingIterator(...)"; |
| 994 | } |
| 995 | }; |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * Deletes and returns the next value from the iterator, or returns |