Stay organized with collections
Save and categorize content based on your preferences.
PrimitiveIterator
interface PrimitiveIterator<T : Any!, T_CONS : Any!> : MutableIterator<T>
A base type for primitive specializations of Iterator
. Specialized subtypes are provided for int
, long
, and double
values.
The specialized subtype default implementations of Iterator.next
and Iterator.forEachRemaining(java.util.function.Consumer)
box primitive values to instances of their corresponding wrapper class. Such boxing may offset any advantages gained when using the primitive specializations. To avoid boxing, the corresponding primitive-based methods should be used. For example, PrimitiveIterator.OfInt.nextInt()
and PrimitiveIterator.OfInt.forEachRemaining(java.util.function.IntConsumer)
should be used in preference to PrimitiveIterator.OfInt.next()
and PrimitiveIterator.OfInt.forEachRemaining(java.util.function.Consumer)
.
Iteration of primitive values using boxing-based methods next()
and forEachRemaining()
, does not affect the order in which the values, transformed to boxed values, are encountered.
Summary
Nested classes |
abstract |
An Iterator specialized for double values.
|
abstract |
An Iterator specialized for int values.
|
abstract |
An Iterator specialized for long values.
|
Public methods |
abstract Unit |
Performs the given action for each remaining element until all elements have been processed or the action throws an exception.
|
Public methods
forEachRemaining
abstract fun forEachRemaining(action: T_CONS): Unit
Performs the given action for each remaining element 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 an iterator is unspecified if the action modifies the source of elements in any way (even by calling the remove
method or other mutator methods of Iterator
subtypes), unless an overriding class has specified a concurrent modification policy.
Subsequent behavior of an iterator is unspecified if the action throws an exception.
Parameters |
action |
T_CONS: The action to be performed for each element |
Exceptions |
java.lang.NullPointerException |
if the specified action is null |
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,["# PrimitiveIterator\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nPrimitiveIterator\n=================\n\n```\ninterface PrimitiveIterator\u003cT : Any!, T_CONS : Any!\u003e : MutableIterator\u003cT\u003e\n```\n\n|----------------------------------|\n| [java.util.PrimitiveIterator](#) |\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [PrimitiveIterator.OfDouble](/reference/kotlin/java/util/PrimitiveIterator.OfDouble), [PrimitiveIterator.OfInt](/reference/kotlin/java/util/PrimitiveIterator.OfInt), [PrimitiveIterator.OfLong](/reference/kotlin/java/util/PrimitiveIterator.OfLong) |--------------------------------------------------------------------------------------|----------------------------------------------| | [PrimitiveIterator.OfDouble](/reference/kotlin/java/util/PrimitiveIterator.OfDouble) | An Iterator specialized for `double` values. | | [PrimitiveIterator.OfInt](/reference/kotlin/java/util/PrimitiveIterator.OfInt) | An Iterator specialized for `int` values. | | [PrimitiveIterator.OfLong](/reference/kotlin/java/util/PrimitiveIterator.OfLong) | An Iterator specialized for `long` values. | |\n\nA base type for primitive specializations of `Iterator`. Specialized subtypes are provided for [int](/reference/kotlin/java/util/PrimitiveIterator.OfInt), [long](/reference/kotlin/java/util/PrimitiveIterator.OfLong), and [double](/reference/kotlin/java/util/PrimitiveIterator.OfDouble) values.\n\nThe specialized subtype default implementations of [Iterator.next](/reference/kotlin/java/util/Iterator#next()) and [Iterator.forEachRemaining(java.util.function.Consumer)](/reference/kotlin/java/util/Iterator#forEachRemaining(java.util.function.Consumer)) box primitive values to instances of their corresponding wrapper class. Such boxing may offset any advantages gained when using the primitive specializations. To avoid boxing, the corresponding primitive-based methods should be used. For example, [PrimitiveIterator.OfInt.nextInt()](/reference/kotlin/java/util/PrimitiveIterator.OfInt#nextInt()) and [PrimitiveIterator.OfInt.forEachRemaining(java.util.function.IntConsumer)](/reference/kotlin/java/util/PrimitiveIterator.OfInt#forEachRemaining(java.util.function.IntConsumer)) should be used in preference to [PrimitiveIterator.OfInt.next()](/reference/kotlin/java/util/PrimitiveIterator.OfInt#next()) and [PrimitiveIterator.OfInt.forEachRemaining(java.util.function.Consumer)](/reference/kotlin/java/util/PrimitiveIterator.OfInt#forEachRemaining(java.util.function.Consumer)).\n\nIteration of primitive values using boxing-based methods [next()](/reference/kotlin/java/util/Iterator#next()) and [forEachRemaining()](/reference/kotlin/java/util/Iterator#forEachRemaining(java.util.function.Consumer)), does not affect the order in which the values, transformed to boxed values, are encountered.\n\nSummary\n-------\n\n| Nested classes ||\n|----------|-----------------------------------------------------------------------------------------------------------------|\n| abstract | [OfDouble](/reference/kotlin/java/util/PrimitiveIterator.OfDouble) An Iterator specialized for `double` values. |\n| abstract | [OfInt](/reference/kotlin/java/util/PrimitiveIterator.OfInt) An Iterator specialized for `int` values. |\n| abstract | [OfLong](/reference/kotlin/java/util/PrimitiveIterator.OfLong) An Iterator specialized for `long` values. |\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [forEachRemaining](#forEachRemaining(java.util.PrimitiveIterator.T_CONS))`(`action:` `T_CONS`)` Performs the given action for each remaining element until all elements have been processed or the action throws an exception. |\n\nPublic methods\n--------------\n\n### forEachRemaining\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun forEachRemaining(action: T_CONS): Unit\n```\n\nPerforms the given action for each remaining element 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 an iterator is unspecified if the action modifies the source of elements in any way (even by calling the [remove](/reference/kotlin/java/util/Iterator#remove()) method or other mutator methods of `Iterator` subtypes), unless an overriding class has specified a concurrent modification policy.\n\nSubsequent behavior of an iterator is unspecified if the action throws an exception.\n\n| Parameters ||\n|----------|-----------------------------------------------------|\n| `action` | T_CONS: The action to be performed for each element |\n\n| Exceptions ||\n|----------------------------------|---------------------------------|\n| `java.lang.NullPointerException` | if the specified action is null |"]]