Collections

Arrays splitrator() Int in Java Code With Examples

Table of Contents

Program

import java.util.Arrays;
import java.util.Spliterator;
public class ArraysSplitratorInt 
{
	public static void main(String[] args) 
	{
		int[] arr = { 1, 2, 3, 4, 5 };
		Spliterator<Integer> s1 = Arrays.spliterator(arr);
		System.out.println("1. Spliterator (int []array) :-");
		s1.forEachRemaining(System.out::println);
		System.out.println("");
		Spliterator<Integer> s2 = Arrays.spliterator(arr, 0, 3);
		System.out.println("2. Spliterator (int []array,Startinclusive,Endexclusive)");
		s2.forEachRemaining(System.out::println);
	}
}

Output

 1. Spliterator (int []array) :-
1
2
3
4
5

2. Spliterator (int []array,Startinclusive,Endexclusive)
1
2
3 

Description

public static Spliterator.OfInt spliterator​(int[] array)

Returns a Spliterator.OfInt covering all of the specified array.
The spliterator reports Spliterator.SIZED, Spliterator.SUBSIZED, Spliterator.ORDERED, and
Spliterator.IMMUTABLE.

Parameters:

array – the array, assumed to be unmodified during use

Returns:

a spliterator for the array elements

public static Spliterator.OfInt spliterator​(int[] array, int startInclusive, int endExclusive)

Returns a Spliterator.OfInt covering the specified range of the specified array.
The spliterator reports Spliterator.SIZED, Spliterator.SUBSIZED, Spliterator.ORDERED, and Spliterator.IMMUTABLE.

Parameters:

array – the array, assumed to be unmodified during use
startInclusive – the first index to cover, inclusive
endExclusive – index immediately past the last index to cover

Returns:

a spliterator for the array elements

Throws:

ArrayIndexOutOfBoundsException – if startInclusive is negative, endExclusive is less than startInclusive,
or endExclusive is greater than the array size