Stay organized with collections
Save and categorize content based on your preferences.
Iterable
interface Iterable<T : Any!>
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 |
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
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
abstract fun iterator(): MutableIterator<T>
Returns an iterator over elements of type T
.
spliterator
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 . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Iterable\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nIterable\n========\n\n```\ninterface Iterable\u003cT : Any!\u003e\n```\n\n|-------------------------|\n| [java.lang.Iterable](#) |\n\nImplementing this interface allows an object to be the target of the enhanced `for` statement (sometimes called the \"for-each loop\" statement).\n\nSummary\n-------\n\n| Public methods ||\n|-------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [forEach](#forEach(java.util.function.Consumer))`(`action:` `[Consumer](../util/function/Consumer.html#)\u003cin` `T\u003e`)` Performs the given action for each element of the `Iterable` until all elements have been processed or the action throws an exception. |\n| abstract [MutableIterator](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-iterator/index.html)\\\u003cT\\\u003e | [iterator](#iterator())`()` Returns an iterator over elements of type `T`. |\n| open [Spliterator](../util/Spliterator.html#)\\\u003cT\\\u003e | [spliterator](#spliterator())`()` Creates a [Spliterator](../util/Spliterator.html#) over the elements described by this `Iterable`. |\n\nPublic methods\n--------------\n\n### forEach\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun forEach(action: Consumer\u003cin T\u003e): Unit\n```\n\nPerforms 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.\n\nThe 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.\n\n| Parameters ||\n|----------|--------------------------------------------------------------------------------------------------|\n| `action` | [Consumer](../util/function/Consumer.html#)\\\u003cin T\\\u003e: The action to be performed for each element |\n\n| Exceptions ||\n|----------------------------------|---------------------------------|\n| `java.lang.NullPointerException` | if the specified action is null |\n\n### iterator\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun iterator(): MutableIterator\u003cT\u003e\n```\n\nReturns an iterator over elements of type `T`.\n\n| Return ||\n|--------------------------------------------------------------------------------------------------------------------|--------------|\n| [MutableIterator](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-iterator/index.html)\u003cT\u003e | an Iterator. |\n\n### spliterator\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun spliterator(): Spliterator\u003cT\u003e\n```\n\nCreates a [Spliterator](../util/Spliterator.html#) over the elements described by this `Iterable`.\n\n| Return ||\n|---------------------------------------------|-----------------------------------------------------------------|\n| [Spliterator](../util/Spliterator.html#)\u003cT\u003e | a `Spliterator` over the elements described by this `Iterable`. |"]]