Skip to content

io microsphere collection EmptyIterator

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

EmptyIterator

Type: Class | Module: microsphere-java-core | Package: io.microsphere.collection

Source: microsphere-java-core/src/main/java/io/microsphere/collection/EmptyIterator.java

Overview

An empty and immutable implementation of the Iterator interface.

This class provides a singleton instance through the public static field #INSTANCE, which can be used directly without creating additional instances. It is safe for use in multi-threaded environments since it does not maintain any mutable state.

Example Usage

`// Using the singleton instance
Iterator iterator = EmptyIterator.INSTANCE;

// Iterating over the empty iterator
while (iterator.hasNext()) {
    String next = iterator.next(); // Will never enter the loop
`

// Attempting to remove from the iterator will throw an exception
try {
    iterator.remove();
} catch (UnsupportedOperationException e) {
    System.out.println("Cannot modify an empty, immutable iterator.");
}
}

Declaration

public class EmptyIterator<E> extends DelegatingIterator<E>

Author: Mercy

Version Information

  • Introduced in: 0.1.10-SNAPSHOT (current)
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// Using the singleton instance
Iterator<String> iterator = EmptyIterator.INSTANCE;

// Iterating over the empty iterator
while (iterator.hasNext()) {
    String next = iterator.next(); // Will never enter the loop
}

// Attempting to remove from the iterator will throw an exception
try {
    iterator.remove();
} catch (UnsupportedOperationException e) {
    System.out.println("Cannot modify an empty, immutable iterator.");
}

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.collection.EmptyIterator;

See Also

  • Iterator
  • Collections#emptyIterator()

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally