Added in API level 1

Iterable

interface Iterable<T : Any!>
java.lang.Iterable

Implementing this interface allows an object to be the target of the enhanced for statement (sometimes called the "for-each loop" statement).

Summary

Public methods
open Unit
forEach(action: Consumer<in T>)

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

abstract MutableIterator<T>

Returns an iterator over elements of type T.

open Spliterator<T>

Creates a Spliterator over the elements described by this Iterable.

Public methods

forEach

Added in API level 24
open fun forEach(action: Consumer<in T>): Unit

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception. Actions are performed in the order of iteration, if that order is specified. Exceptions thrown by the action are relayed to the caller.

The behavior of this method is unspecified if the action performs side-effects that modify the underlying source of elements, unless an overriding class has specified a concurrent modification policy.

Parameters
action Consumer<in T>: The action to be performed for each element
Exceptions
java.lang.NullPointerException if the specified action is null

iterator

Added in API level 1
abstract fun iterator(): MutableIterator<T>

Returns an iterator over elements of type T.

Return
MutableIterator<T> an Iterator.

spliterator

Added in API level 24
open fun spliterator(): Spliterator<T>

Creates a Spliterator over the elements described by this Iterable.

Return
Spliterator<T> a Spliterator over the elements described by this Iterable.