PrimitiveIterator
Stay organized with collections
Save and categorize content based on your preferences.
Known Indirect Subclasses
|
Public Method Summary
abstract
void
|
forEachRemaining(T_CONS action)
Performs the given action for each remaining element, in the order
elements occur when iterating, until all elements have been processed
or the action throws an exception.
|
Inherited Method Summary
From interface
java.util.Iterator
void
|
forEachRemaining( Consumer<? super E> action)
Performs the given action for each remaining element until all elements
have been processed or the action throws an exception.
|
abstract
boolean
|
hasNext()
Returns true if the iteration has more elements.
|
abstract
T
|
next()
Returns the next element in the iteration.
|
void
|
remove()
Removes from the underlying collection the last element returned
by this iterator (optional operation).
|
Public Methods
public
abstract
void
forEachRemaining
(T_CONS action)
Performs the given action for each remaining element, in the order
elements occur when iterating, until all elements have been processed
or the action throws an exception. Errors or runtime exceptions
thrown by the action are relayed to the caller.
Parameters
action |
The action to be performed for each element |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-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 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003ePrimitiveIterator\u003c/code\u003e is a base type for specialized \u003ccode\u003eIterator\u003c/code\u003e implementations for primitive data types (\u003ccode\u003eint\u003c/code\u003e, \u003ccode\u003elong\u003c/code\u003e, and \u003ccode\u003edouble\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eIt provides a mechanism to iterate over primitive values without boxing, enhancing performance.\u003c/p\u003e\n"],["\u003cp\u003eSpecialized subtypes, like \u003ccode\u003ePrimitiveIterator.OfInt\u003c/code\u003e, offer methods such as \u003ccode\u003enextInt()\u003c/code\u003e for direct access to primitive values.\u003c/p\u003e\n"],["\u003cp\u003eWhile default \u003ccode\u003enext()\u003c/code\u003e implementations box primitive values, using primitive-specific methods is recommended for efficiency.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eforEachRemaining()\u003c/code\u003e method processes all remaining elements with a specified action, until completion or an exception is encountered.\u003c/p\u003e\n"]]],["`PrimitiveIterator` is a base type for specialized iterators handling `int`, `long`, and `double` primitives. It implements `Iterator`, with subtypes like `OfInt`, `OfLong`, and `OfDouble`. It includes `forEachRemaining(T_CONS action)` method to process remaining elements. Subtypes offer methods like `nextInt()`, avoiding boxing. While `next()` and `forEachRemaining()` cause boxing, their order remains consistent. Inherited methods from `Iterator` include `hasNext()`, `next()`, and `remove()`. The `forEachRemaining()` method processes each element until completion or an exception.\n"],null,["public interface **PrimitiveIterator** implements [Iterator](../../../reference/java/util/Iterator.html)\\\u003cT\\\u003e \n\n|---|---|---|\n| Known Indirect Subclasses [PrimitiveIterator.OfDouble](../../../reference/java/util/PrimitiveIterator.OfDouble.html), [PrimitiveIterator.OfInt](../../../reference/java/util/PrimitiveIterator.OfInt.html), [PrimitiveIterator.OfLong](../../../reference/java/util/PrimitiveIterator.OfLong.html) |--------------------------------------------------------------------------------------------|----------------------------------------------| | [PrimitiveIterator.OfDouble](../../../reference/java/util/PrimitiveIterator.OfDouble.html) | An Iterator specialized for `double` values. | | [PrimitiveIterator.OfInt](../../../reference/java/util/PrimitiveIterator.OfInt.html) | An Iterator specialized for `int` values. | | [PrimitiveIterator.OfLong](../../../reference/java/util/PrimitiveIterator.OfLong.html) | An Iterator specialized for `long` values. | |||\n\nA base type for primitive specializations of `Iterator`. Specialized\nsubtypes are provided for [int](../../../reference/java/util/PrimitiveIterator.OfInt.html), [long](../../../reference/java/util/PrimitiveIterator.OfLong.html), and\n[double](../../../reference/java/util/PrimitiveIterator.OfDouble.html) values.\n\nThe specialized subtype default implementations of [Iterator.next()](../../../reference/java/util/Iterator.html#next())\nand [Iterator.forEachRemaining(java.util.function.Consumer)](../../../reference/java/util/Iterator.html#forEachRemaining(java.util.function.Consumer\u003c?%20super%20E\u003e)) box\nprimitive values to instances of their corresponding wrapper class. Such\nboxing may offset any advantages gained when using the primitive\nspecializations. To avoid boxing, the corresponding primitive-based methods\nshould be used. For example, [PrimitiveIterator.OfInt.nextInt()](../../../reference/java/util/PrimitiveIterator.OfInt.html#nextInt()) and\n[PrimitiveIterator.OfInt.forEachRemaining(java.util.function.IntConsumer)](../../../reference/java/util/PrimitiveIterator.OfInt.html#forEachRemaining(java.util.function.IntConsumer))\nshould be used in preference to [PrimitiveIterator.OfInt.next()](../../../reference/java/util/PrimitiveIterator.OfInt.html#next()) and\n[Iterator.forEachRemaining(java.util.function.Consumer)](../../../reference/java/util/Iterator.html#forEachRemaining(java.util.function.Consumer\u003c?%20super%20E\u003e)).\n\nIteration of primitive values using boxing-based methods\n[next()](../../../reference/java/util/Iterator.html#next()) and\n[forEachRemaining()](../../../reference/java/util/Iterator.html#forEachRemaining(java.util.function.Consumer\u003c?%20super%20E\u003e)),\ndoes not affect the order in which the values, transformed to boxed values,\nare encountered. \n\nNested Class Summary\n\n|-----------|---|---|----------------------------------------------|\n| interface | [PrimitiveIterator.OfDouble](../../../reference/java/util/PrimitiveIterator.OfDouble.html) || An Iterator specialized for `double` values. |\n| interface | [PrimitiveIterator.OfInt](../../../reference/java/util/PrimitiveIterator.OfInt.html) || An Iterator specialized for `int` values. |\n| interface | [PrimitiveIterator.OfLong](../../../reference/java/util/PrimitiveIterator.OfLong.html) || An Iterator specialized for `long` values. |\n\nPublic Method Summary\n\n|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [forEachRemaining](../../../reference/java/util/PrimitiveIterator.html#forEachRemaining(T_CONS))(T_CONS action) Performs the given action for each remaining element, in the order elements occur when iterating, until all elements have been processed or the action throws an exception. |\n\nInherited Method Summary \nFrom interface [java.util.Iterator](../../../reference/java/util/Iterator.html) \n\n|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| void | [forEachRemaining](../../../reference/java/util/Iterator.html#forEachRemaining(java.util.function.Consumer\u003c?%20super%20E\u003e))([Consumer](../../../reference/java/util/function/Consumer.html)\\\u003c? super E\\\u003e action) Performs the given action for each remaining element until all elements have been processed or the action throws an exception. |\n| abstract boolean | [hasNext](../../../reference/java/util/Iterator.html#hasNext())() Returns `true` if the iteration has more elements. |\n| abstract T | [next](../../../reference/java/util/Iterator.html#next())() Returns the next element in the iteration. |\n| void | [remove](../../../reference/java/util/Iterator.html#remove())() Removes from the underlying collection the last element returned by this iterator (optional operation). |\n\nPublic Methods \n\npublic abstract void\n**forEachRemaining**\n(T_CONS action) \nPerforms the given action for each remaining element, in the order\nelements occur when iterating, until all elements have been processed\nor the action throws an exception. Errors or runtime exceptions\nthrown by the action are relayed to the caller. \n\nParameters\n\n| action | The action to be performed for each element |\n|--------|---------------------------------------------|\n\nThrows\n\n| [NullPointerException](../../../reference/java/lang/NullPointerException.html) | if the specified action is null |\n|--------------------------------------------------------------------------------|---------------------------------|"]]