Spliterator.OfPrimitive (Java SE 26 & JDK 26)
Description: declaration: module: java.base, package: java.util, interface: Spliterator, interface: OfPrimitive
Keywords: java.util.Spliterator.OfPrimitive interface

# Interface Spliterator.OfPrimitive<T, T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T,T_CONS,T_SPLITR>>

Type Parameters:
  `T` - the type of elements returned by this Spliterator. 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 `Consumer` for `T`, such as `IntConsumer` for `Integer`.
  `T_SPLITR` - the type of primitive Spliterator. The type must be a primitive specialization of Spliterator for `T`, such as `Spliterator.OfInt` for `Integer`.

All Superinterfaces:
  `Spliterator<T>`

All Known Subinterfaces:
  `Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong`

All Known Implementing Classes:
  `Spliterators.AbstractDoubleSpliterator, Spliterators.AbstractIntSpliterator, Spliterators.AbstractLongSpliterator`

Enclosing interface:
  `Spliterator<T>`

public static interface Spliterator.OfPrimitive<T, T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T,T_CONS,T_SPLITR>> extends Spliterator<T>
A Spliterator specialized for primitive values.

Since:
  1.8
See Also:
  - `Spliterator.OfInt`
  - `Spliterator.OfLong`
  - `Spliterator.OfDouble`

- ## Nested Class Summary

  ### Nested classes/interfaces declared in interface Spliterator

  `Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T,T_CONS,T_SPLITR>`
  Modifier and Type
  Interface
  Description
  `static interface`
  `Spliterator.OfDouble`
  A Spliterator specialized for `double` values.
  `static interface`
  `Spliterator.OfInt`
  A Spliterator specialized for `int` values.
  `static interface`
  `Spliterator.OfLong`
  A Spliterator specialized for `long` values.
  `static interface`
  `Spliterator.OfPrimitive<T, T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T,T_CONS,T_SPLITR>>`
  A Spliterator specialized for primitive values.

- ## Field Summary

  ### Fields declared in interface Spliterator

  `CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED`
  Modifier and Type
  Field
  Description
  `static final int`
  `CONCURRENT`
  Characteristic value signifying that the element source may be safely concurrently modified (allowing additions, replacements, and/or removals) by multiple threads without external synchronization.
  `static final int`
  `DISTINCT`
  Characteristic value signifying that, for each pair of encountered elements `x, y`, `!x.equals(y)`.
  `static final int`
  `IMMUTABLE`
  Characteristic value signifying that the element source cannot be structurally modified; that is, elements cannot be added, replaced, or removed, so such changes cannot occur during traversal.
  `static final int`
  `NONNULL`
  Characteristic value signifying that the source guarantees that encountered elements will not be `null`.
  `static final int`
  `ORDERED`
  Characteristic value signifying that an encounter order is defined for elements.
  `static final int`
  `SIZED`
  Characteristic value signifying that the value returned from `estimateSize()` prior to traversal or splitting represents a finite size that, in the absence of structural source modification, represents an exact count of the number of elements that would be encountered by a complete traversal.
  `static final int`
  `SORTED`
  Characteristic value signifying that encounter order follows a defined sort order.
  `static final int`
  `SUBSIZED`
  Characteristic value signifying that all Spliterators resulting from `trySplit()` will be both `Spliterator.SIZED` and `Spliterator.SUBSIZED`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default void`
  `forEachRemaining(T_CONS action)`
  Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.
  `boolean`
  `tryAdvance(T_CONS action)`
  If a remaining element exists, performs the given action on it, returning `true`; else returns `false`.

  ### Methods declared in interface Spliterator

  `characteristics, estimateSize, forEachRemaining, getComparator, getExactSizeIfKnown, hasCharacteristics, tryAdvance, trySplit`
  Modifier and Type
  Method
  Description
  `int`
  `characteristics()`
  Returns a set of characteristics of this Spliterator and its elements.
  `long`
  `estimateSize()`
  Returns an estimate of the number of elements that would be encountered by a `Spliterator.forEachRemaining(Consumer)` traversal, or returns `Long.MAX_VALUE` if infinite, unknown, or too expensive to compute.
  `default void`
  `forEachRemaining(Consumer<? super T> action)`
  Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.
  `default Comparator<? super T>`
  `getComparator()`
  If this Spliterator's source is `Spliterator.SORTED` by a `Comparator`, returns that `Comparator`.
  `default long`
  `getExactSizeIfKnown()`
  Convenience method that returns `Spliterator.estimateSize()` if this Spliterator is `Spliterator.SIZED`, else `-1`.
  `default boolean`
  `hasCharacteristics(int characteristics)`
  Returns `true` if this Spliterator's `Spliterator.characteristics()` contain all of the given characteristics.
  `boolean`
  `tryAdvance(Consumer<? super T> action)`
  If a remaining element exists: performs the given action on it, returning `true`; else returns `false`.
  `Spliterator<T>`
  `trySplit()`
  If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.

- ## Method Details

  - ### tryAdvance

    boolean tryAdvance(T_CONS action)
    If a remaining element exists, performs the given action on it, returning `true`; else returns `false`. If this Spliterator is `Spliterator.ORDERED` the action is performed on the next element in encounter order. Exceptions thrown by the action are relayed to the caller.

    Subsequent behavior of a spliterator is unspecified if the action throws an exception.

    Parameters:
      `action` - The action
    Returns:
      `false` if no remaining elements existed upon entry to this method, else `true`.
    Throws:
      `NullPointerException` - if the specified action is null

  - ### forEachRemaining

    default void forEachRemaining(T_CONS action)
    Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception. If this Spliterator is `Spliterator.ORDERED`, actions are performed in encounter order. Exceptions thrown by the action are relayed to the caller.

    Subsequent behavior of a spliterator is unspecified if the action throws an exception.

    Implementation Requirements:
      The default implementation repeatedly invokes `tryAdvance(T_CONS)` until it returns `false`. It should be overridden whenever possible.
    Parameters:
      `action` - The action
    Throws:
      `NullPointerException` - if the specified action is null