Class UnmodifiableIterator<E>

  • All Implemented Interfaces:
    Iterator<E>, Unmodifiable

    public final class UnmodifiableIterator<E>
    extends Object
    implements Iterator<E>, Unmodifiable
    Decorates an iterator such that it cannot be modified.

    Attempts to modify it will result in an UnsupportedOperationException.

    • Method Detail

      • unmodifiableIterator

        public static <E> Iterator<E> unmodifiableIterator​(Iterator<? extends E> iterator)
        Decorates the specified iterator such that it cannot be modified.

        If the iterator is already unmodifiable it is returned directly.

        Type Parameters:
        E - the element type
        iterator - the iterator to decorate
        a new unmodifiable iterator
        NullPointerException - if the iterator is null
      • hasNext

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

        public E next()
        Specified by:
        next in interface Iterator<E>
      • remove

        public void remove()
        Specified by:
        remove in interface Iterator<E>