public final class PrimitiveArrayExtensions extends Object
int
, long
, float
, and double
.Modifier and Type | Method and Description |
---|---|
static DoubleIterable |
asDoubleIterable(double[] arr)
This method creates an
IntIterable for the given array arr ,
allowing iteration over the complete array via a primitive iterator or a stream. |
static DoubleIterable |
asDoubleIterable(double[] arr,
int startIncluding,
int endExcluding)
This method provides an unmodifiable view as a
DoubleIterable on a slice of the
array arr . |
static IntIterable |
asIntIterable(int[] arr)
This method creates an
IntIterable for the given array arr ,
allowing iteration over all elements in the array via a primitive iterator or a stream. |
static IntIterable |
asIntIterable(int[] arr,
int startIncluding,
int endExcluding)
This method provides an unmodifiable view as a
IntIterable on a slice of the
array arr . |
static LongIterable |
asLongIterable(long[] arr)
This method creates an
IntIterable for the given array arr ,
allowing iteration over the complete array via a primitive iterator or a stream. |
static LongIterable |
asLongIterable(long[] arr,
int startIncluding,
int endExcluding)
This method provides an unmodifiable view as a
LongIterable on a slice of the
array arr . |
static void |
forEachDouble(double[] arr,
DoubleConsumer consumer)
This method allows iterating over the primitive values in the given array
arr without boxing the values into objects. |
static void |
forEachInt(int[] arr,
IntConsumer consumer)
This method allows iterating over the primitive values in the given array
arr without boxing the values into objects. |
static void |
forEachLong(long[] arr,
LongConsumer consumer)
This method allows iterating over the primitive values in the given array
arr without boxing the values into objects. |
public static IntIterable asIntIterable(int[] arr)
IntIterable
for the given array arr
,
allowing iteration over all elements in the array via a primitive iterator or a stream.arr
- array to create an iterable for.int
values of the given array arr
.public static IntIterable asIntIterable(int[] arr, int startIncluding, int endExcluding) throws IllegalArgumentException, IndexOutOfBoundsException
IntIterable
on a slice of the
array arr
. The slice will start at the array index of startIncluding
and
and at the array index of endExcluding - 1
. If startIncluding == endExcluding
an empty iterable is returned.
Note that at the current point negative values for the index parameters are not supported and will cause this
method to throw an exception. This may change in later releases.arr
- the array to create a IntIterable
view for.startIncluding
- the index of the array where the iterable will start. Must be >=0
and
< arr.length
.endExcluding
- the index of the last element to be iterated over in the array +1. E.g. if the
last element of the array should be the last element to be iterated over, this parameter must be
arr.length
. The value must be >= 0
and <= arr.length
. If value is 0
then startIncluding
must be 0
as well; in this case an empty IntIterable
is returned.int
values of input array arr
specified via
startIncluding
and endExcluding
IllegalArgumentException
- if startIncluding > endExcluding
.IndexOutOfBoundsException
- if either startIncluding
or endExcluding
refer to an index out of the range of array arr
.public static LongIterable asLongIterable(long[] arr)
IntIterable
for the given array arr
,
allowing iteration over the complete array via a primitive iterator or a stream.arr
- array to create an iterable for.arr
.public static LongIterable asLongIterable(long[] arr, int startIncluding, int endExcluding) throws IllegalArgumentException, IndexOutOfBoundsException
LongIterable
on a slice of the
array arr
. The slice will start at the array index of startIncluding
and
and at the array index of endExcluding - 1
. If startIncluding == endExcluding
an empty iterable is returned.
Note that at the current point negative values for the index parameters are not supported and will cause this method
to throw an exception. This may change in later releases.arr
- the array to create a LongIterable
view for.startIncluding
- the index of the array where the iterable will start. Must be >=0
and
< arr.length
.endExcluding
- the index of the last element to be iterated over in the array +1. E.g. if the
last element of the array should be the last element to be iterated over, this parameter must be
arr.length
. The value must be >= 0
and <= arr.length
. If value is 0
then startIncluding
must be 0
as well; in this case an empty LongIterable
is returned.long
values of input array arr
specified via
startIncluding
and endExcluding
IllegalArgumentException
- if startIncluding > endExcluding
.IndexOutOfBoundsException
- if either startIncluding
or endExcluding
refer to an index out of the range of array arr
.public static DoubleIterable asDoubleIterable(double[] arr)
IntIterable
for the given array arr
,
allowing iteration over the complete array via a primitive iterator or a stream.arr
- array to create an iterable for.arr
.public static DoubleIterable asDoubleIterable(double[] arr, int startIncluding, int endExcluding) throws IllegalArgumentException, IndexOutOfBoundsException
DoubleIterable
on a slice of the
array arr
. The slice will start at the array index of startIncluding
and
and at the array index of endExcluding - 1
. If startIncluding == endExcluding
an empty iterable is returned.
Note that at the current point negative values for the index parameters are not supported and will cause this method
to throw an exception. This may change in later releases.arr
- the array to create a DoubleIterable
view for.startIncluding
- the index of the array where the iterable will start. Must be >=0
and
< arr.length
.endExcluding
- the index of the last element to be iterated over in the array +1. E.g. if the
last element of the array should be the last element to be iterated over, this parameter must be
arr.length
. The value must be >= 0
and <= arr.length
. If value is 0
then startIncluding
must be 0
as well; in this case an empty DoubleIterable
is returned.double
values of input array arr
specified via
startIncluding
and endExcluding
IllegalArgumentException
- if startIncluding > endExcluding
.IndexOutOfBoundsException
- if either startIncluding
or endExcluding
refer to an index out of the range of array arr
.public static void forEachInt(int[] arr, IntConsumer consumer)
arr
without boxing the values into objects.
For each elements in the array (from index 0
to arr.length - 1
) the given consumer
is called with every element.arr
- array to iterate overconsumer
- the action called with each element in arr
.public static void forEachLong(long[] arr, LongConsumer consumer)
arr
without boxing the values into objects.
For each elements in the array (from index 0
to arr.length - 1
) the given consumer
is called with every element.arr
- array to iterate overconsumer
- the action called with each element in arr
.public static void forEachDouble(double[] arr, DoubleConsumer consumer)
arr
without boxing the values into objects.
For each elements in the array (from index 0
to arr.length - 1
) the given consumer
is called with every element.arr
- array to iterate overconsumer
- the action called with each element in arr
.Copyright © 2019. All rights reserved.