public final class Iterables
extends java.lang.Object
Iterable
interface.Modifier and Type | Method and Description |
---|---|
static <T> void |
forEach(java.lang.Iterable<? extends T> it,
Consumer<? super T> action)
Performs the given action for each element of the
Iterable
until all elements have been processed or the action throws an
exception. |
static <T> Spliterator<T> |
spliterator(java.lang.Iterable<? extends T> it)
Creates a
Spliterator over the elements described by this
Iterable . |
public static <T> void forEach(java.lang.Iterable<? extends T> it, Consumer<? super T> action)
Iterable
until all elements have been processed or the action throws an
exception. Unless otherwise specified by the implementing class,
actions are performed in the order of iteration (if an iteration order
is specified). Exceptions thrown by the action are relayed to the
caller.
Implementation Requirements:
The default implementation behaves as if:
for (T t : this)
action.accept(t);
T
- the type of elements of the Iterableit
- the Iterable to call forEach
onaction
- The action to be performed for each elementjava.lang.NullPointerException
- if the specified action is nullpublic static <T> Spliterator<T> spliterator(java.lang.Iterable<? extends T> it)
Spliterator
over the elements described by this
Iterable
.
Implementation Requirements:
The default implementation creates an
early-binding
spliterator from the iterable's Iterator
. The spliterator
inherits the fail-fast properties of the iterable's iterator.
Implementation Note:
The default implementation should usually be overridden. The
spliterator returned by the default implementation has poor splitting
capabilities, is unsized, and does not report any spliterator
characteristics. Implementing classes can nearly always provide a
better implementation.
T
- the type of elements of the Iterable.it
- the Iterable for which the Spliterator should be created.Spliterator
over the elements described by this
Iterable
.