Java Arrays spliterator(double[] a)Method



Description

The Java Arrays spliterator(double[] a) method returns a Spliterator.OfDouble covering all of the specified array.

Declaration

Following is the declaration for java.util.Arrays.spliterator(double[] a) method

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

Parameters

a − This is the array, assumed to be unmodified during use.

Return Value

This method returns a spliterator for the array elements.

Exception

NA

Java Arrays spliterator​(double[] a, int fromIndex, int toIndex) Method

Description

The Java Arrays spliterator(double[] a, int fromIndex, int toIndex) method returns a Spliterator.OfDouble covering the specified range of the specified array.

Declaration

Following is the declaration for java.util.Arrays.spliterator(double[] a, int fromIndex, int toIndex) method

public static Spliterator.OfDouble spliterator​(double[] array, int fromIndex, int toIndex)

Parameters

  • a − This is the array, assumed to be unmodified during use.

  • fromIndex − This is the index of the first element, inclusive, to be covered.

  • toIndex − This is the index of the last element, exclusive, to be covered

Return Value

This method returns a spliterator for the array elements.

Exception

  • ArrayIndexOutOfBoundsException − if fromIndex < 0 or toIndex > array.length

Getting Spliterator of Array of doubles Example

The following example shows the usage of Java Arrays spliterator(double[]) method. First, we've created an array of doubles. Using spliterator() method, array is printed thereafter.

package com.tutorialspoint;

import java.util.Arrays;
import java.util.Spliterator;

public class ArrayDemo {
   public static void main(String[] args) {
      // initialize array
      double arr[] = { 11.0, 54.0, 23.0, 32.0, 15.0, 24.0, 31.0, 12.0 };

      System.out.print("Array: [ ");
      
      // get the spliterator
      Spliterator<Double> spliterator = Arrays.spliterator(arr);

      // use the spliterator to print each item
      spliterator.forEachRemaining(i -> System.out.print(i + " "));
      
      System.out.print("]");
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Array: [ 11.0 54.0 23.0 32.0 15.0 24.0 31.0 12.0 ]

Getting Spliterator of Array of doubles using Range Example

The following example shows the usage of Java Arrays spliterator(double[], int, int) method. First, we've created an array of doubles. Using spliterator() method, array is printed thereafter.

package com.tutorialspoint;

import java.util.Arrays;
import java.util.Spliterator;

public class ArrayDemo {
   public static void main(String[] args) {
      // initialize array
      double arr[] = { 11.0, 54.0, 23.0, 32.0, 15.0, 24.0, 31.0, 12.0 };

      System.out.print("Array: [ ");
      
      // get the spliterator
      Spliterator<Double> spliterator = Arrays.spliterator(arr, 0, arr.length);

      // use the spliterator to print each item
      spliterator.forEachRemaining(i -> System.out.print(i + " "));
      
      System.out.print("]");
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Array: [ 11.0 54.0 23.0 32.0 15.0 24.0 31.0 12.0 ]

Getting Spliterator of Sub-Array of doubles Example

The following example shows the usage of Java Arrays spliterator(double[], int, int) method. First, we've created an array of doubles. Using spliterator() method, a sub-array is printed thereafter.

package com.tutorialspoint;

import java.util.Arrays;
import java.util.Spliterator;

public class ArrayDemo {
   public static void main(String[] args) {
      // initialize array
      double arr[] = { 11.0, 54.0, 23.0, 32.0, 15.0, 24.0, 31.0, 12.0 };

      System.out.print("Array: [ ");
      
      // get the spliterator
      Spliterator<Double> spliterator = Arrays.spliterator(arr, 0, 5);

      // use the spliterator to print each item
      spliterator.forEachRemaining(i -> System.out.print(i + " "));
      
      System.out.print("]");
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Array: [ 11.0 54.0 23.0 32.0 15.0 ]
java_util_arrays.htm
Advertisements