Class DelegatingIterator<E>

  • Type Parameters:
    E - the type of elements returned by this iterator
    All Implemented Interfaces:
    DelegatingWrapper, Wrapper, java.util.Iterator<E>
    Direct Known Subclasses:
    EmptyIterator

    public class DelegatingIterator<E>
    extends java.lang.Object
    implements java.util.Iterator<E>, DelegatingWrapper
    A delegating implementation of the Iterator interface that forwards all method calls to a delegate iterator. This class is useful when you want to wrap an existing iterator and potentially override some of its behavior.

    Example Usage

    
     List<String> list = Arrays.asList("a", "b", "c");
     Iterator<String> iterator = new DelegatingIterator<>(list.iterator());
     while (iterator.hasNext()) {
         System.out.println(iterator.next());
     }
     
    Author:
    Mercy
    See Also:
    Iterator
    • Constructor Detail

      • DelegatingIterator

        public DelegatingIterator​(java.util.Iterator<E> delegate)
    • Method Detail

      • hasNext

        public final boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<E>
      • next

        public final E next()
        Specified by:
        next in interface java.util.Iterator<E>
      • remove

        public final void remove()
        Specified by:
        remove in interface java.util.Iterator<E>
      • forEachRemaining

        public final void forEachRemaining​(java.util.function.Consumer<? super E> action)
        Specified by:
        forEachRemaining in interface java.util.Iterator<E>
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public final boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object