Package io.microsphere.collection
Class UnmodifiableIterator<E>
- java.lang.Object
-
- io.microsphere.collection.ReadOnlyIterator<E>
-
- io.microsphere.collection.UnmodifiableIterator<E>
-
- Type Parameters:
E- the type of elements returned by this iterator
- All Implemented Interfaces:
java.util.Iterator<E>
@Immutable public class UnmodifiableIterator<E> extends ReadOnlyIterator<E>
AnIteratorthat is unmodifiable, meaning the elements cannot be removed. This class extends theReadOnlyIterator, which throws an exception when the remove operation is attempted.Example Usage
List
list = Arrays.asList("one", "two", "three"); Iterator unmodifiableIterator = new UnmodifiableIterator<>(list.iterator()); while (unmodifiableIterator.hasNext()) { System.out.println(unmodifiableIterator.next()); } // Attempting to remove will throw an IllegalStateException try { unmodifiableIterator.remove(); } catch (IllegalStateException e) { System.out.println("Cannot remove elements from an unmodifiable iterator."); } - Since:
- 1.0.0
- Author:
- Mercy
-
-
Constructor Summary
Constructors Constructor Description UnmodifiableIterator(java.util.Iterator<E> delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidforEachRemaining(java.util.function.Consumer<? super E> action)booleanhasNext()Enext()-
Methods inherited from class io.microsphere.collection.ReadOnlyIterator
remove
-
-