APIdia Launch Partner
Top Description Inners Methods
java.util

public Interface PrimitiveIterator<T, T_CONS>

extends Iterator<T>
Known Direct Subinterfaces
java.util.PrimitiveIterator.OfInt, java.util.PrimitiveIterator.OfLong, java.util.PrimitiveIterator.OfDouble
Type Parameters
<T>
the type of elements returned by this PrimitiveIterator. The type must be a wrapper type for a primitive type, such as Integer for the primitive int type.
<T_CONS>
the type of primitive consumer. The type must be a primitive specialization of java.util.function.Consumer for T, such as java.util.function.IntConsumer for Integer.
Imports
java.util.function.Consumer, .DoubleConsumer, .IntConsumer, .LongConsumer

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 to true then diagnostic warnings are reported if boxing of primitive values occur when operating on primitive subtype specializations.

Since
1.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
PrimitiveIterator.OfDouble

An Iterator specialized for double values.

public static interface
PrimitiveIterator.OfInt

An Iterator specialized for int values.

public static interface
PrimitiveIterator.OfLong

An Iterator specialized for long values.

Method Summary

Modifier and TypeMethod and Description
public void
forEachRemaining(T_CONS
The action to be performed for each element
action
)

Performs the given action for each remaining element until all elements have been processed or the action throws an exception.

Inherited from java.util.Iterator:
forEachRemaininghasNextnextremove

Method Detail

forEachRemainingback to summary
public void forEachRemaining(T_CONS 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.

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
NullPointerException:
if the specified action is null
java.util back to summary

public Interface PrimitiveIterator.OfDouble

extends PrimitiveIterator<Double, DoubleConsumer>
Annotations
@SuppressWarnings:overloads

An Iterator specialized for double values.
Since
1.8

Method Summary

Modifier and TypeMethod and Description
public default void
forEachRemaining(DoubleConsumer action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Performs the given action for each remaining element until all elements have been processed or the action throws an exception.

public default void
forEachRemaining(Consumer<? super Double> action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Performs the given action for each remaining element until all elements have been processed or the action throws an exception.

public default Double
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public double

Returns:

the next double element in the iteration
nextDouble
()

Returns the next double element in the iteration.

Method Detail

forEachRemainingback to summary
public default void forEachRemaining(DoubleConsumer action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Doc from java.util.PrimitiveIterator.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 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.

Implementation Specification

The default implementation behaves as if:

while (hasNext())
        action.accept(nextDouble());
forEachRemainingback to summary
public default void forEachRemaining(Consumer<? super Double> action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Doc from java.util.PrimitiveIterator.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 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.

Implementation Specification

If the action is an instance of DoubleConsumer then it is cast to DoubleConsumer and passed to forEachRemaining; otherwise the action is adapted to an instance of DoubleConsumer, by boxing the argument of DoubleConsumer, and then passed to forEachRemaining.

Annotations
@Override
nextback to summary
public default Double next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Implementation Specification

The default implementation boxes the result of calling nextDouble(), and returns that boxed result.

Annotations
@Override
nextDoubleback to summary
public double nextDouble()

Returns the next double element in the iteration.

Returns:double

the next double element in the iteration

Exceptions
NoSuchElementException:
if the iteration has no more elements
java.util back to summary

public Interface PrimitiveIterator.OfInt

extends PrimitiveIterator<Integer, IntConsumer>
Annotations
@SuppressWarnings:overloads

An Iterator specialized for int values.
Since
1.8

Method Summary

Modifier and TypeMethod and Description
public default void
forEachRemaining(IntConsumer action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Performs the given action for each remaining element until all elements have been processed or the action throws an exception.

public default void
forEachRemaining(Consumer<? super Integer> action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Performs the given action for each remaining element until all elements have been processed or the action throws an exception.

public default Integer
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public int

Returns:

the next int element in the iteration
nextInt
()

Returns the next int element in the iteration.

Method Detail

forEachRemainingback to summary
public default void forEachRemaining(IntConsumer action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Doc from java.util.PrimitiveIterator.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 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.

Implementation Specification

The default implementation behaves as if:

while (hasNext())
        action.accept(nextInt());
forEachRemainingback to summary
public default void forEachRemaining(Consumer<? super Integer> action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Doc from java.util.PrimitiveIterator.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 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.

Implementation Specification

If the action is an instance of IntConsumer then it is cast to IntConsumer and passed to forEachRemaining; otherwise the action is adapted to an instance of IntConsumer, by boxing the argument of IntConsumer, and then passed to forEachRemaining.

Annotations
@Override
nextback to summary
public default Integer next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Implementation Specification

The default implementation boxes the result of calling nextInt(), and returns that boxed result.

Annotations
@Override
nextIntback to summary
public int nextInt()

Returns the next int element in the iteration.

Returns:int

the next int element in the iteration

Exceptions
NoSuchElementException:
if the iteration has no more elements
java.util back to summary

public Interface PrimitiveIterator.OfLong

extends PrimitiveIterator<Long, LongConsumer>
Annotations
@SuppressWarnings:overloads

An Iterator specialized for long values.
Since
1.8

Method Summary

Modifier and TypeMethod and Description
public default void
forEachRemaining(LongConsumer action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Performs the given action for each remaining element until all elements have been processed or the action throws an exception.

public default void
forEachRemaining(Consumer<? super Long> action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Performs the given action for each remaining element until all elements have been processed or the action throws an exception.

public default Long
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public long

Returns:

the next long element in the iteration
nextLong
()

Returns the next long element in the iteration.

Method Detail

forEachRemainingback to summary
public default void forEachRemaining(LongConsumer action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Doc from java.util.PrimitiveIterator.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 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.

Implementation Specification

The default implementation behaves as if:

while (hasNext())
        action.accept(nextLong());
forEachRemainingback to summary
public default void forEachRemaining(Consumer<? super Long> action)

Implements java.util.PrimitiveIterator.forEachRemaining.

Doc from java.util.PrimitiveIterator.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 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.

Implementation Specification

If the action is an instance of LongConsumer then it is cast to LongConsumer and passed to forEachRemaining; otherwise the action is adapted to an instance of LongConsumer, by boxing the argument of LongConsumer, and then passed to forEachRemaining.

Annotations
@Override
nextback to summary
public default Long next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Implementation Specification

The default implementation boxes the result of calling nextLong(), and returns that boxed result.

Annotations
@Override
nextLongback to summary
public long nextLong()

Returns the next long element in the iteration.

Returns:long

the next long element in the iteration

Exceptions
NoSuchElementException:
if the iteration has no more elements