Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/java/util/PrimitiveIterator#nestedclasses) \| [Methods](https://developer.android.com/reference/java/util/PrimitiveIterator#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/util/PrimitiveIterator#inhmethods)

# PrimitiveIterator

` public interface PrimitiveIterator `   
` implements https://developer.android.com/reference/java/util/Iterator<T> `

|---|
| java.util.PrimitiveIterator\<T, T_CONS\> |

Known indirect subclasses [PrimitiveIterator.OfDouble](https://developer.android.com/reference/java/util/PrimitiveIterator.OfDouble), [PrimitiveIterator.OfInt](https://developer.android.com/reference/java/util/PrimitiveIterator.OfInt), [PrimitiveIterator.OfLong](https://developer.android.com/reference/java/util/PrimitiveIterator.OfLong) [PrimitiveIterator.OfDouble](https://developer.android.com/reference/java/util/PrimitiveIterator.OfDouble) An Iterator specialized for `double` values. [PrimitiveIterator.OfInt](https://developer.android.com/reference/java/util/PrimitiveIterator.OfInt) An Iterator specialized for `int` values. [PrimitiveIterator.OfLong](https://developer.android.com/reference/java/util/PrimitiveIterator.OfLong) An Iterator specialized for `long` values.   

*** ** * ** ***

A base type for primitive specializations of `Iterator`. Specialized subtypes are provided for `https://developer.android.com/reference/java/util/PrimitiveIterator.OfInt`, `https://developer.android.com/reference/java/util/PrimitiveIterator.OfLong`, and `https://developer.android.com/reference/java/util/PrimitiveIterator.OfDouble` values.

The specialized subtype default implementations of `https://developer.android.com/reference/java/util/Iterator#next()` and `https://developer.android.com/reference/java/util/Iterator#forEachRemaining(java.util.function.Consumer<?%20super%20E>)` 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, `https://developer.android.com/reference/java/util/PrimitiveIterator.OfInt#nextInt()` and `https://developer.android.com/reference/java/util/PrimitiveIterator.OfInt#forEachRemaining(java.util.function.IntConsumer)` should be used in preference to `https://developer.android.com/reference/java/util/PrimitiveIterator.OfInt#next()` and `https://developer.android.com/reference/java/util/Iterator#forEachRemaining(java.util.function.Consumer<?%20super%20E>)`.

Iteration of primitive values using boxing-based methods `https://developer.android.com/reference/java/util/Iterator#next()` and `https://developer.android.com/reference/java/util/Iterator#forEachRemaining(java.util.function.Consumer<?%20super%20E>)`, does not affect the order in which the values, transformed to boxed values, are encountered.

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/java/util/PrimitiveIterator.OfDouble` An Iterator specialized for `double` values. |
| ` interface` | `https://developer.android.com/reference/java/util/PrimitiveIterator.OfInt` An Iterator specialized for `int` values. |
| ` interface` | `https://developer.android.com/reference/java/util/PrimitiveIterator.OfLong` An Iterator specialized for `long` values. |

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/java/util/PrimitiveIterator#forEachRemaining(T_CONS)(T_CONS action) ` Performs the given action for each remaining element until all elements have been processed or the action throws an exception. |

### Inherited methods

From interface ` https://developer.android.com/reference/java/util/Iterator ` ` default void` ` https://developer.android.com/reference/java/util/Iterator#forEachRemaining(java.util.function.Consumer<?%20super%20E>)(https://developer.android.com/reference/java/util/function/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` ` https://developer.android.com/reference/java/util/Iterator#hasNext()() `

Returns `true` if the iteration has more elements.
` abstract T` ` https://developer.android.com/reference/java/util/Iterator#next()() `

Returns the next element in the iteration.
` default void` ` https://developer.android.com/reference/java/util/Iterator#remove()() `

Removes from the underlying collection the last element returned by this iterator (optional operation).

## Public methods

### forEachRemaining

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract 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 `https://developer.android.com/reference/java/util/Iterator#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.

<br />

| Parameters ||
|---|---|
| `action` | `T_CONS`: The action to be performed for each element <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified action is null |