Class SingletonIterator<E>

  • Type Parameters:
    E - the type of the element returned by this iterator
    All Implemented Interfaces:
    java.util.Iterator<E>

    @Immutable
    public class SingletonIterator<E>
    extends ReadOnlyIterator<E>
    A specialized read-only Iterator implementation that iterates over a single element.

    This iterator is useful when you need to expose an Iterator interface for a single element, ensuring that the underlying element cannot be modified or removed during iteration due to its read-only nature.

    Since:
    1.0.0
    Author:
    Mercy
    • Constructor Summary

      Constructors 
      Constructor Description
      SingletonIterator​(E element)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void forEachRemaining​(java.util.function.Consumer<? super E> action)  
      boolean hasNext()  
      E next()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SingletonIterator

        public SingletonIterator​(E element)
    • Method Detail

      • hasNext

        public boolean hasNext()
      • next

        public E next()
      • forEachRemaining

        public void forEachRemaining​(java.util.function.Consumer<? super E> action)