Skip to content

io microsphere util IterableUtils

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

IterableUtils

Type: Class | Module: microsphere-java-core | Package: io.microsphere.util | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/util/IterableUtils.java

Overview

The utility class for Iterable

Declaration

public abstract class IterableUtils implements Utils

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • 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

Method Examples

isIterable

List<String> list = Arrays.asList("a", "b", "c");
boolean result1 = IterableUtils.isIterable(list);     // true
boolean result2 = IterableUtils.isIterable("string"); // false
boolean result3 = IterableUtils.isIterable(null);     // false

isIterable

boolean result1 = IterableUtils.isIterable(List.class);  // true
boolean result2 = IterableUtils.isIterable(String.class); // false
boolean result3 = IterableUtils.isIterable(null);        // false

iterate

List<String> list = Arrays.asList("a", "b", "c");
IterableUtils.iterate(list, System.out::println);
// Output:
// a
// b
// c

forEach

List<String> list = Arrays.asList("a", "b", "c");
IterableUtils.forEach(list, System.out::println);
// Output:
// a
// b
// c

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.util.IterableUtils;

API Reference

Public Methods

Method Description
isIterable Checks if the given object is an instance of Iterable.
isIterable Checks if the given class is assignable from Iterable.
iterate Iterates over the given Iterable and applies the provided Consumer to each element.
forEach Iterates over the given Iterable and applies the provided Consumer to each element.

Method Details

isIterable

public static boolean isIterable(@Nullable Object object)

Checks if the given object is an instance of Iterable.

Example Usage

`List list = Arrays.asList("a", "b", "c");
boolean result1 = IterableUtils.isIterable(list);     // true
boolean result2 = IterableUtils.isIterable("string"); // false
boolean result3 = IterableUtils.isIterable(null);     // false
`

isIterable

public static boolean isIterable(@Nullable Class<?> clazz)

Checks if the given class is assignable from Iterable.

Example Usage

`boolean result1 = IterableUtils.isIterable(List.class);  // true
boolean result2 = IterableUtils.isIterable(String.class); // false
boolean result3 = IterableUtils.isIterable(null);        // false
`

iterate

public static <E> void iterate(@Nullable Iterable<E> elements, @Nonnull Consumer<E> elementConsumer)

Iterates over the given Iterable and applies the provided Consumer to each element.

Example Usage

`List list = Arrays.asList("a", "b", "c");
IterableUtils.iterate(list, System.out::println);
// Output:
// a
// b
// c
`

forEach

public static <E> void forEach(@Nullable Iterable<E> elements, @Nonnull Consumer<E> elementConsumer)

Iterates over the given Iterable and applies the provided Consumer to each element.

This method is equivalent to #iterate(Iterable, Consumer).

Example Usage

`List list = Arrays.asList("a", "b", "c");
IterableUtils.forEach(list, System.out::println);
// Output:
// a
// b
// c
`

See Also

  • Iterable

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