Java Utility Library

Java Arrays - spliterator() Method



The java.util.Arrays.spliterator() method returns a Spliterator.OfDouble covering all of the specified array.

Syntax

public static Spliterator.OfDouble spliterator(double[] array)

Parameters

array Specify the array, assumed to be unmodified during use.

Return Value

Returns a spliterator for the array elements.

Exception

NA.

Example:

In the example below, the java.util.Arrays.spliterator() method returns a Double spliterator with all elements of the specified array.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a double array
    double MyArr[] = {10.1, 2.34, -3.6, 35.01, 56.23};

    //creating spliterator object on Array 
    Spliterator<Double> splitr = Arrays.spliterator(MyArr); 

    //printing estimateSize of the Array
    System.out.println("Estimated size: " + splitr.estimateSize());  

    //display content of the Array using 
    //tryAdvance method
    System.out.print("The Array contains: ");              
    splitr.forEachRemaining((n) -> System.out.print(n + " "));    
  }
}

The output of the above code will be:

Estimated size: 5
The Array contains: 10.1 2.34 -3.6 35.01 56.23 

❮ Java.util - Arrays