PrimitiveIterator.OfInt
Stay organized with collections
Save and categorize content based on your preferences.
An Iterator specialized for int
values.
Public Method Summary
void
|
|
void
|
forEachRemaining( IntConsumer action)
Performs the given action for each remaining element until all elements
have been processed or the action throws an exception.
|
Integer
|
next()
Returns the next element in the iteration.
|
abstract
int
|
nextInt()
Returns the next int element in the iteration.
|
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
Integer
|
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
void
forEachRemaining
(IntConsumer action)
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.
Parameters
action |
The action to be performed for each element |
public
Integer
next
()
Returns the next element in the iteration.
Returns
- the next element in the iteration
public
abstract
int
nextInt
()
Returns the next int
element in the iteration.
Returns
- the next
int
element in the iteration
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.OfInt\u003c/code\u003e is an iterator specifically designed for handling \u003ccode\u003eint\u003c/code\u003e values.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods like \u003ccode\u003enextInt()\u003c/code\u003e to directly retrieve the next \u003ccode\u003eint\u003c/code\u003e element and \u003ccode\u003eforEachRemaining()\u003c/code\u003e to process remaining elements.\u003c/p\u003e\n"],["\u003cp\u003eThis iterator inherits functionalities from \u003ccode\u003ePrimitiveIterator\u003c/code\u003e and \u003ccode\u003eIterator\u003c/code\u003e, offering methods like \u003ccode\u003ehasNext()\u003c/code\u003e, \u003ccode\u003enext()\u003c/code\u003e, and \u003ccode\u003eremove()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eforEachRemaining()\u003c/code\u003e method can accept both \u003ccode\u003eConsumer<Integer>\u003c/code\u003e and \u003ccode\u003eIntConsumer\u003c/code\u003e for processing elements.\u003c/p\u003e\n"],["\u003cp\u003eIf there are no more elements to iterate, calling \u003ccode\u003enextInt()\u003c/code\u003e will result in a \u003ccode\u003eNoSuchElementException\u003c/code\u003e.\u003c/p\u003e\n"]]],["`PrimitiveIterator.OfInt` is a specialized iterator for `int` values. Key actions include `forEachRemaining(IntConsumer action)`, which applies an action to remaining elements, and `nextInt()`, which retrieves the next `int` element. It also inherits `forEachRemaining` and `next()` which acts on consumer and return the next element. `hasNext()` checks for more elements and `remove()` allows for element removal. Errors such as `NullPointerException` and `NoSuchElementException` can be thrown.\n"],null,["# PrimitiveIterator.OfInt\n\npublic static interface **PrimitiveIterator.OfInt** implements [PrimitiveIterator](../../../reference/java/util/PrimitiveIterator.html)\\\u003c[Integer](../../../reference/java/lang/Integer.html), [IntConsumer](../../../reference/java/util/function/IntConsumer.html)\\\u003e \nAn Iterator specialized for `int` values. \n\n### Public Method Summary\n\n|------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| void | [forEachRemaining](../../../reference/java/util/PrimitiveIterator.OfInt.html#forEachRemaining(java.util.function.Consumer\u003c?%20super%20java.lang.Integer\u003e))([Consumer](../../../reference/java/util/function/Consumer.html)\\\u003c? super [Integer](../../../reference/java/lang/Integer.html)\\\u003e action) |\n| void | [forEachRemaining](../../../reference/java/util/PrimitiveIterator.OfInt.html#forEachRemaining(java.util.function.IntConsumer))([IntConsumer](../../../reference/java/util/function/IntConsumer.html) action) Performs the given action for each remaining element until all elements have been processed or the action throws an exception. |\n| [Integer](../../../reference/java/lang/Integer.html) | [next](../../../reference/java/util/PrimitiveIterator.OfInt.html#next())() Returns the next element in the iteration. |\n| abstract int | [nextInt](../../../reference/java/util/PrimitiveIterator.OfInt.html#nextInt())() Returns the next `int` element in the iteration. |\n\n### Inherited Method Summary\n\nFrom interface [java.util.PrimitiveIterator](../../../reference/java/util/PrimitiveIterator.html) \n\n|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [forEachRemaining](../../../reference/java/util/PrimitiveIterator.html#forEachRemaining(T_CONS))([IntConsumer](../../../reference/java/util/function/IntConsumer.html) 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\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 [Integer](../../../reference/java/lang/Integer.html) | [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--------------\n\n#### public void\n**forEachRemaining**\n([Consumer](../../../reference/java/util/function/Consumer.html)\\\u003c? super [Integer](../../../reference/java/lang/Integer.html)\\\u003e action)\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| action | |\n|--------|---|\n\n#### public void\n**forEachRemaining**\n([IntConsumer](../../../reference/java/util/function/IntConsumer.html) action)\n\nPerforms the given action for each remaining element until all elements\nhave been processed or the action throws an exception. Actions are\nperformed in the order of iteration, if that order is specified.\nExceptions thrown by the action are relayed to the caller. \n\n##### Parameters\n\n| action | The action to be performed for each element |\n|--------|---------------------------------------------|\n\n##### Throws\n\n| [NullPointerException](../../../reference/java/lang/NullPointerException.html) | if the specified action is null |\n|--------------------------------------------------------------------------------|---------------------------------|\n\n#### public [Integer](../../../reference/java/lang/Integer.html)\n**next**\n()\n\nReturns the next element in the iteration. \n\n##### Returns\n\n- the next element in the iteration \n\n#### public abstract int\n**nextInt**\n()\n\nReturns the next `int` element in the iteration. \n\n##### Returns\n\n- the next `int` element in the iteration \n\n##### Throws\n\n| [NoSuchElementException](../../../reference/java/util/NoSuchElementException.html) | if the iteration has no more elements |\n|------------------------------------------------------------------------------------|---------------------------------------|"]]