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
Iterator
. Specialized subtypes are provided forint
,long
, anddouble
values.The specialized subtype default implementations ofIterator.next()
andIterator.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()
andPrimitiveIterator.OfInt.forEachRemaining(java.util.function.IntConsumer)
should be used in preference toPrimitiveIterator.OfInt.next()
andPrimitiveIterator.OfInt.forEachRemaining(java.util.function.Consumer)
.
Iteration of primitive values using boxing-based methodsnext()
andforEachRemaining()
, 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 Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
An Iterator specialized fordouble
values.static interface
An Iterator specialized forint
values.static interface
An Iterator specialized forlong
values.Method Summary
Modifier and TypeMethodDescriptionvoid
forEachRemaining
(T_CONS action) Performs the given action for each remaining element until all elements have been processed or the action throws an exception.Methods declared in interface java.util.Iterator
forEachRemaining,hasNext,next,remove
Method Details
forEachRemaining
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 ofIterator
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
- The action to be performed for each element- Throws:
NullPointerException
- if the specified action is null