Interface PrimitiveIterator<T,T_CONS>
- Type Parameters:
-
T
- the type of elements returned by this PrimitiveIterator. The type must be a wrapper type for a primitive type, such asInteger
for the primitiveint
type. -
T_CONS
- the type of primitive consumer. The type must be a primitive specialization ofConsumer
forT
, such asIntConsumer
forInteger
.
- All Superinterfaces:
Iterator<T>
- All Known Subinterfaces:
-
PrimitiveIterator.OfDouble
,PrimitiveIterator.OfInt
,PrimitiveIterator.OfLong
public interface PrimitiveIterator<T,T_CONS> extends Iterator<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.
- Implementation Note:
- If the boolean system property
org.openjdk.java.util.stream.tripwire
is set totrue
then diagnostic warnings are reported if boxing of primitive values occur when operating on primitive subtype specializations. - Since:
- 1.8
Nested Classes
Modifier and Type | Interface | Description |
---|---|---|
static interface | PrimitiveIterator.OfDouble | An Iterator specialized for |
static interface | PrimitiveIterator.OfInt | An Iterator specialized for |
static interface | PrimitiveIterator.OfLong | An Iterator specialized for |
Methods
Modifier and Type | Method | Description |
---|---|---|
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. |
Methods declared in interface java.util.Iterator
forEachRemaining, hasNext, next, remove
Methods
forEachRemaining
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 - Throws:
-
NullPointerException
- if the specified action is null
© 1993, 2020, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/PrimitiveIterator.html