Class IntStreamEx
 Object

 IntStreamEx

 All Implemented Interfaces:
AutoCloseable
,BaseStream<Integer,IntStream>
,IntStream
public class IntStreamEx extends Object implements IntStream
AnIntStream
implementation with additional functionality Author:
 Tagir Valeev


Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
IntStreamEx.IntEmitter
A helper interface to build a new stream by emitting elements and creating new emitters in a chain.
Nested classes/interfaces inherited from interface IntStream
IntStream.Builder


Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allMatch(IntPredicate predicate)
boolean
anyMatch(IntPredicate predicate)
IntStreamEx
append(int... values)
Returns a newIntStreamEx
which is a concatenation of this stream and the stream containing supplied valuesIntStreamEx
append(IntStream other)
Creates a lazily concatenated stream whose elements are all the elements of this stream followed by all the elements of the other stream.InputStream
asByteInputStream()
Returns anInputStream
lazily populated from the currentIntStreamEx
.DoubleStreamEx
asDoubleStream()
LongStreamEx
asLongStream()
IntStreamEx
atLeast(int value)
Returns a stream consisting of the elements of this stream that greater than or equal to the specified value.IntStreamEx
atMost(int value)
Returns a stream consisting of the elements of this stream that less than or equal to the specified value.OptionalDouble
average()
StreamEx<Integer>
boxed()
<U> U
chain(Function<? super IntStreamEx,U> mapper)
Applies the supplied function to this stream and returns the result of the function.String
charsToString()
Returns aString
consisting of chars from this stream.void
close()
String
codePointsToString()
Returns aString
consisting of code points from this stream.<R> R
collect(Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R,R> combiner)
<A,R>
Rcollect(IntCollector<A,R> collector)
Performs a mutable reduction operation on the elements of this stream using anIntCollector
which encapsulates the supplier, accumulator and merger functions making easier to reuse collection strategies.static IntStreamEx
constant(int value, long length)
Returns a sequential unorderedIntStreamEx
of given length which elements are equal to supplied value.long
count()
IntStreamEx
distinct()
IntStreamEx
dropWhile(IntPredicate predicate)
Returns a stream consisting of all elements from this stream starting from the first element which does not match the given predicate.DoubleStreamEx
elements(double[] array)
Returns aDoubleStreamEx
consisting of the elements of given array corresponding to the indices which appear in this stream.IntStreamEx
elements(int[] array)
Returns anIntStreamEx
consisting of the elements of given array corresponding to the indices which appear in this stream.LongStreamEx
elements(long[] array)
Returns aLongStreamEx
consisting of the elements of given array corresponding to the indices which appear in this stream.<U> StreamEx<U>
elements(List<U> list)
<U> StreamEx<U>
elements(U[] array)
Returns an objectvaluedStreamEx
consisting of the elements of given array corresponding to the indices which appear in this stream.static IntStreamEx
empty()
Returns an empty sequentialIntStreamEx
.IntStreamEx
filter(IntPredicate predicate)
OptionalInt
findAny()
OptionalInt
findAny(IntPredicate predicate)
Returns anOptionalInt
describing some element of the stream, which matches given predicate, or an emptyOptionalInt
if there's no matching element.OptionalInt
findFirst()
OptionalInt
findFirst(IntPredicate predicate)
Returns anOptionalInt
describing the first element of this stream, which matches given predicate, or an emptyOptionalInt
if there's no matching element.IntStreamEx
flatMap(IntFunction<? extends IntStream> mapper)
DoubleStreamEx
flatMapToDouble(IntFunction<? extends DoubleStream> mapper)
Returns aDoubleStreamEx
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.LongStreamEx
flatMapToLong(IntFunction<? extends LongStream> mapper)
Returns aLongStreamEx
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.<R> StreamEx<R>
flatMapToObj(IntFunction<? extends Stream<R>> mapper)
Returns aStreamEx
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.int
foldLeft(int seed, IntBinaryOperator accumulator)
Folds the elements of this stream using the provided seed object and accumulation function, going left to right.OptionalInt
foldLeft(IntBinaryOperator accumulator)
Folds the elements of this stream using the provided accumulation function, going left to right.void
forEach(IntConsumer action)
void
forEachOrdered(IntConsumer action)
static IntStreamEx
generate(IntSupplier s)
Returns an infinite sequential unordered stream where each element is generated by the providedIntSupplier
.IntStreamEx
greater(int value)
Returns a stream consisting of the elements of this stream that strictly greater than the specified value.boolean
has(int value)
Returns true if this stream contains the specified value.OptionalLong
indexOf(int value)
Returns anOptionalLong
describing the zerobased index of the first element of this stream, which equals to the given value, or an emptyOptionalLong
if there's no matching element.OptionalLong
indexOf(IntPredicate predicate)
Returns anOptionalLong
describing the zerobased index of the first element of this stream, which matches given predicate, or an emptyOptionalLong
if there's no matching element.IntStreamEx
intersperse(int delimiter)
Returns a new stream containing all the elements of the original stream interspersed with given delimiter.static IntStreamEx
ints()
Returns a sequential orderedIntStreamEx
from 0 (inclusive) toInteger.MAX_VALUE
(exclusive) by an incremental step of1
.boolean
isParallel()
static IntStreamEx
iterate(int seed, IntPredicate predicate, IntUnaryOperator f)
Returns a sequential orderedIntStreamEx
produced by iterative application of a function to an initial element, conditioned on satisfying the supplied predicate.static IntStreamEx
iterate(int seed, IntUnaryOperator f)
Returns an infinite sequential orderedIntStreamEx
produced by iterative application of a functionf
to an initial elementseed
, producing a stream consisting ofseed
,f(seed)
,f(f(seed))
, etc.PrimitiveIterator.OfInt
iterator()
String
joining(CharSequence delimiter)
Returns aString
which is the concatenation of the results of callingString.valueOf(int)
on each element of this stream, separated by the specified delimiter, in encounter order.String
joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
Returns aString
which is the concatenation of the results of callingString.valueOf(int)
on each element of this stream, separated by the specified delimiter, with the specified prefix and suffix in encounter order.IntStreamEx
less(int value)
Returns a stream consisting of the elements of this stream that strictly less than the specified value.IntStreamEx
limit(long maxSize)
IntStreamEx
map(IntUnaryOperator mapper)
IntStreamEx
mapFirst(IntUnaryOperator mapper)
Returns a stream where the first element is the replaced with the result of applying the given function while the other elements are left intact.IntStreamEx
mapLast(IntUnaryOperator mapper)
Returns a stream where the last element is the replaced with the result of applying the given function while the other elements are left intact.DoubleStreamEx
mapToDouble(IntToDoubleFunction mapper)
<K,V>
EntryStream<K,V>mapToEntry(IntFunction<? extends K> keyMapper, IntFunction<? extends V> valueMapper)
Returns anEntryStream
consisting of theMap.Entry
objects which keys and values are results of applying the given functions to the elements of this stream.LongStreamEx
mapToLong(IntToLongFunction mapper)
<U> StreamEx<U>
mapToObj(IntFunction<? extends U> mapper)
OptionalInt
max()
OptionalInt
max(Comparator<Integer> comparator)
Returns the maximum element of this stream according to the providedComparator
.<V extends Comparable<? super V>>
OptionalIntmaxBy(IntFunction<V> keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.OptionalInt
maxByDouble(IntToDoubleFunction keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.OptionalInt
maxByInt(IntUnaryOperator keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.OptionalInt
maxByLong(IntToLongFunction keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.OptionalInt
min()
OptionalInt
min(Comparator<Integer> comparator)
Returns the minimum element of this stream according to the providedComparator
.<V extends Comparable<? super V>>
OptionalIntminBy(IntFunction<V> keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.OptionalInt
minByDouble(IntToDoubleFunction keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.OptionalInt
minByInt(IntUnaryOperator keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.OptionalInt
minByLong(IntToLongFunction keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.boolean
noneMatch(IntPredicate predicate)
static IntStreamEx
of(byte... elements)
Returns a sequential orderedIntStreamEx
whose elements are the specified values casted to int.static IntStreamEx
of(byte[] array, int startInclusive, int endExclusive)
Returns a sequentialIntStreamEx
with the specified range of the specified array as its source.static IntStreamEx
of(char... elements)
Returns a sequential orderedIntStreamEx
whose elements are the specified values casted to int.static IntStreamEx
of(char[] array, int startInclusive, int endExclusive)
Returns a sequentialIntStreamEx
with the specified range of the specified array as its source.static IntStreamEx
of(int element)
Returns a sequentialIntStreamEx
containing a single element.static IntStreamEx
of(int... elements)
Returns a sequential orderedIntStreamEx
whose elements are the specified values.static IntStreamEx
of(int[] array, int startInclusive, int endExclusive)
Returns a sequentialIntStreamEx
with the specified range of the specified array as its source.static IntStreamEx
of(short... elements)
Returns a sequential orderedIntStreamEx
whose elements are the specified values casted to int.static IntStreamEx
of(short[] array, int startInclusive, int endExclusive)
Returns a sequentialIntStreamEx
with the specified range of the specified array as its source.static IntStreamEx
of(InputStream is)
Returns a sequential orderedIntStreamEx
backed by the content of givenInputStream
.static IntStreamEx
of(Integer[] array)
Returns a sequential orderedIntStreamEx
whose elements are the unboxed elements of supplied array.static IntStreamEx
of(IntBuffer buf)
Returns a sequential orderedIntStreamEx
whose elements are the values in the suppliedIntBuffer
.static IntStreamEx
of(BitSet bitSet)
Returns anIntStreamEx
of indices for which the specifiedBitSet
contains a bit in the set state.static IntStreamEx
of(Collection<Integer> collection)
Returns a sequential orderedIntStreamEx
whose elements are the unboxed elements of supplied collection.static IntStreamEx
of(OptionalInt optional)
Returns a sequentialIntStreamEx
containing anOptionalInt
value, if present, otherwise returns an emptyIntStreamEx
.static IntStreamEx
of(PrimitiveIterator.OfInt iterator)
Returns a sequential, orderedIntStreamEx
created from givenPrimitiveIterator.OfInt
.static IntStreamEx
of(Random random)
Returns an effectively unlimited stream of pseudorandomint
values produced by givenRandom
object.static IntStreamEx
of(Random random, int randomNumberOrigin, int randomNumberBound)
Returns an effectively unlimited stream of pseudorandomint
values, each conforming to the given origin (inclusive) and bound (exclusive).static IntStreamEx
of(Random random, long streamSize)
Returns a stream producing the givenstreamSize
number of pseudorandomint
values.static IntStreamEx
of(Random random, long streamSize, int randomNumberOrigin, int randomNumberBound)
Returns a stream producing the givenstreamSize
number of pseudorandomint
values, each conforming to the given origin (inclusive) and bound (exclusive).static IntStreamEx
of(Spliterator.OfInt spliterator)
Returns a sequentialIntStreamEx
created from givenSpliterator.OfInt
.static IntStreamEx
of(IntStream stream)
Returns anIntStreamEx
object which wraps givenIntStream
.static IntStreamEx
ofChars(CharSequence seq)
static IntStreamEx
ofCodePoints(CharSequence seq)
Returns anIntStreamEx
of code point values from the suppliedCharSequence
.static IntStreamEx
ofIndices(double[] array)
Returns a sequential orderedIntStreamEx
containing all the indices of supplied array.static IntStreamEx
ofIndices(double[] array, DoublePredicate predicate)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied array elements which match given predicate.static IntStreamEx
ofIndices(int[] array)
Returns a sequential orderedIntStreamEx
containing all the indices of supplied array.static IntStreamEx
ofIndices(int[] array, IntPredicate predicate)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied array elements which match given predicate.static IntStreamEx
ofIndices(long[] array)
Returns a sequential orderedIntStreamEx
containing all the indices of supplied array.static IntStreamEx
ofIndices(long[] array, LongPredicate predicate)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied array elements which match given predicate.static <T> IntStreamEx
ofIndices(List<T> list)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied list.static <T> IntStreamEx
ofIndices(List<T> list, Predicate<T> predicate)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied list elements which match given predicate.static <T> IntStreamEx
ofIndices(T[] array)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied array.static <T> IntStreamEx
ofIndices(T[] array, Predicate<T> predicate)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied array elements which match given predicate.IntStreamEx
onClose(Runnable closeHandler)
IntStreamEx
pairMap(IntBinaryOperator mapper)
Returns a stream consisting of the results of applying the given function to the every adjacent pair of elements of this stream.IntStreamEx
parallel()
IntStreamEx
parallel(ForkJoinPool fjp)
Returns an equivalent stream that is parallel and bound to the suppliedForkJoinPool
.IntStreamEx
peek(IntConsumer action)
IntStreamEx
peekFirst(IntConsumer action)
Returns a stream consisting of the elements of this stream, additionally performing the provided action on the first stream element when it's consumed from the resulting stream.IntStreamEx
peekLast(IntConsumer action)
Returns a stream consisting of the elements of this stream, additionally performing the provided action on the last stream element when it's consumed from the resulting stream.IntStreamEx
prefix(IntBinaryOperator op)
Returns a stream containing cumulative results of applying the accumulation function going left to right.IntStreamEx
prepend(int... values)
Returns a newIntStreamEx
which is a concatenation of the stream containing supplied values and this streamIntStreamEx
prepend(IntStream other)
Creates a lazily concatenated stream whose elements are all the elements of the other stream followed by all the elements of this stream.static IntStreamEx
produce(Predicate<IntConsumer> producer)
Return an ordered stream produced by consecutive calls of the supplied producer until it returns false.static IntStreamEx
range(int endExclusive)
Returns a sequential orderedIntStreamEx
from 0 (inclusive) toendExclusive
(exclusive) by an incremental step of1
.static IntStreamEx
range(int startInclusive, int endExclusive)
Returns a sequential orderedIntStreamEx
fromstartInclusive
(inclusive) toendExclusive
(exclusive) by an incremental step of1
.static IntStreamEx
range(int startInclusive, int endExclusive, int step)
Returns a sequential orderedIntStreamEx
fromstartInclusive
(inclusive) toendExclusive
(exclusive) by the specified incremental step.static IntStreamEx
rangeClosed(int startInclusive, int endInclusive)
Returns a sequential orderedIntStreamEx
fromstartInclusive
(inclusive) toendInclusive
(inclusive) by an incremental step of1
.static IntStreamEx
rangeClosed(int startInclusive, int endInclusive, int step)
Returns a sequential orderedIntStreamEx
fromstartInclusive
(inclusive) toendInclusive
(inclusive) by the specified incremental step.int
reduce(int identity, IntBinaryOperator op)
OptionalInt
reduce(IntBinaryOperator op)
IntStreamEx
remove(IntPredicate predicate)
Returns a stream consisting of the elements of this stream that don't match the given predicate.IntStreamEx
reverseSorted()
Returns a stream consisting of the elements of this stream in reverse sorted order.int[]
scanLeft(int seed, IntBinaryOperator accumulator)
Produces an array containing cumulative results of applying the accumulation function going left to right using given seed value.int[]
scanLeft(IntBinaryOperator accumulator)
Produces an array containing cumulative results of applying the accumulation function going left to right.IntStreamEx
sequential()
IntStreamEx
skip(long n)
IntStreamEx
sorted()
IntStreamEx
sorted(Comparator<Integer> comparator)
Returns a stream consisting of the elements of this stream sorted according to the given comparator.<V extends Comparable<? super V>>
IntStreamExsortedBy(IntFunction<V> keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the natural order of the keys extracted by provided function.IntStreamEx
sortedByDouble(IntToDoubleFunction keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the double values extracted by provided function.IntStreamEx
sortedByInt(IntUnaryOperator keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the int values extracted by provided function.IntStreamEx
sortedByLong(IntToLongFunction keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the long values extracted by provided function.SPLTR
spliterator()
int
sum()
IntSummaryStatistics
summaryStatistics()
IntStreamEx
takeWhile(IntPredicate predicate)
Returns a stream consisting of all elements from this stream until the first element which does not match the given predicate is found.IntStreamEx
takeWhileInclusive(IntPredicate predicate)
Returns a stream consisting of all elements from this stream until the first element which does not match the given predicate is found (including the first mismatching element).int[]
toArray()
BitSet
toBitSet()
Returns aBitSet
containing the elements of this stream.byte[]
toByteArray()
Returns abyte[]
array containing the elements of this stream which are converted to bytes using(byte)
cast operation.char[]
toCharArray()
Returns achar[]
array containing the elements of this stream which are converted to chars using(char)
cast operation.short[]
toShortArray()
Returns ashort[]
array containing the elements of this stream which are converted to shorts using(short)
cast operation.IntStreamEx
unordered()
IntStreamEx
without(int value)
Returns a stream consisting of the elements of this stream that don't equal to the given value.IntStreamEx
without(int... values)
Returns a stream consisting of the elements of this stream that don't equal to any of the supplied values.static IntStreamEx
zip(int[] first, int[] second, IntBinaryOperator mapper)
Returns a sequentialIntStreamEx
containing the results of applying the given function to the corresponding pairs of values in given two arrays.
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods inherited from interface BaseStream
close, isParallel

Methods inherited from interface IntStream
spliterator




Method Detail

unordered
public IntStreamEx unordered()
 Specified by:
unordered
in interfaceBaseStream<Integer,IntStream>

onClose
public IntStreamEx onClose(Runnable closeHandler)
 Specified by:
onClose
in interfaceBaseStream<Integer,IntStream>

filter
public IntStreamEx filter(IntPredicate predicate)

remove
public IntStreamEx remove(IntPredicate predicate)
Returns a stream consisting of the elements of this stream that don't match the given predicate.This is an intermediate operation.
 Parameters:
predicate
 a noninterfering, stateless predicate to apply to each element to determine if it should be excluded Returns:
 the new stream

has
public boolean has(int value)
Returns true if this stream contains the specified value.This is a shortcircuiting terminal operation.
 Parameters:
value
 the value too look for in the stream Returns:
 true if this stream contains the specified value
 See Also:
IntStream.anyMatch(IntPredicate)

without
public IntStreamEx without(int value)
Returns a stream consisting of the elements of this stream that don't equal to the given value.This is an intermediate operation.
 Parameters:
value
 the value to remove from the stream. Returns:
 the new stream
 Since:
 0.2.2
 See Also:
without(int...)
,remove(IntPredicate)

without
public IntStreamEx without(int... values)
Returns a stream consisting of the elements of this stream that don't equal to any of the supplied values.This is an intermediate operation. May return itself if no values were supplied.
Current implementation scans the supplied values linearly for every stream element.
If the
values
array is changed between calling this method and finishing the stream traversal, then the result of the stream traversal is undefined: changes may or may not be taken into account. Parameters:
values
 the values to remove from the stream. Returns:
 the new stream
 Since:
 0.5.5
 See Also:
without(int)
,remove(IntPredicate)

greater
public IntStreamEx greater(int value)
Returns a stream consisting of the elements of this stream that strictly greater than the specified value.This is an intermediate operation.
 Parameters:
value
 a value to compare to Returns:
 the new stream
 Since:
 0.2.3

atLeast
public IntStreamEx atLeast(int value)
Returns a stream consisting of the elements of this stream that greater than or equal to the specified value.This is an intermediate operation.
 Parameters:
value
 a value to compare to Returns:
 the new stream
 Since:
 0.2.3

less
public IntStreamEx less(int value)
Returns a stream consisting of the elements of this stream that strictly less than the specified value.This is an intermediate operation.
 Parameters:
value
 a value to compare to Returns:
 the new stream
 Since:
 0.2.3

atMost
public IntStreamEx atMost(int value)
Returns a stream consisting of the elements of this stream that less than or equal to the specified value.This is an intermediate operation.
 Parameters:
value
 a value to compare to Returns:
 the new stream
 Since:
 0.2.3

map
public IntStreamEx map(IntUnaryOperator mapper)

mapToObj
public <U> StreamEx<U> mapToObj(IntFunction<? extends U> mapper)

mapToLong
public LongStreamEx mapToLong(IntToLongFunction mapper)

mapToDouble
public DoubleStreamEx mapToDouble(IntToDoubleFunction mapper)
 Specified by:
mapToDouble
in interfaceIntStream

mapToEntry
public <K,V> EntryStream<K,V> mapToEntry(IntFunction<? extends K> keyMapper, IntFunction<? extends V> valueMapper)
Returns anEntryStream
consisting of theMap.Entry
objects which keys and values are results of applying the given functions to the elements of this stream.This is an intermediate operation.
 Type Parameters:
K
 TheEntry
key typeV
 TheEntry
value type Parameters:
keyMapper
 a noninterfering, stateless function to apply to each elementvalueMapper
 a noninterfering, stateless function to apply to each element Returns:
 the new stream
 Since:
 0.3.1

flatMap
public IntStreamEx flatMap(IntFunction<? extends IntStream> mapper)

flatMapToLong
public LongStreamEx flatMapToLong(IntFunction<? extends LongStream> mapper)
Returns aLongStreamEx
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
 Parameters:
mapper
 a noninterfering, stateless function to apply to each element which produces aLongStream
of new values Returns:
 the new stream
 Since:
 0.3.0

flatMapToDouble
public DoubleStreamEx flatMapToDouble(IntFunction<? extends DoubleStream> mapper)
Returns aDoubleStreamEx
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
 Parameters:
mapper
 a noninterfering, stateless function to apply to each element which produces aDoubleStream
of new values Returns:
 the new stream
 Since:
 0.3.0

flatMapToObj
public <R> StreamEx<R> flatMapToObj(IntFunction<? extends Stream<R>> mapper)
Returns aStreamEx
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
 Type Parameters:
R
 The element type of the new stream Parameters:
mapper
 a noninterfering, stateless function to apply to each element which produces aStream
of new values Returns:
 the new stream
 Since:
 0.3.0

intersperse
public IntStreamEx intersperse(int delimiter)
Returns a new stream containing all the elements of the original stream interspersed with given delimiter.For example,
IntStreamEx.of(1, 2, 3).intersperse(4)
will yield a stream containing five elements: 1, 4, 2, 4, 3.This is an intermediate operation.
 Parameters:
delimiter
 a delimiter to be inserted between each pair of elements Returns:
 the new stream
 Since:
 0.6.6

distinct
public IntStreamEx distinct()

sorted
public IntStreamEx sorted()

sorted
public IntStreamEx sorted(Comparator<Integer> comparator)
Returns a stream consisting of the elements of this stream sorted according to the given comparator. Stream elements are boxed before passing to the comparator.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
 Parameters:
comparator
 a noninterfering , statelessComparator
to be used to compare stream elements Returns:
 the new stream

reverseSorted
public IntStreamEx reverseSorted()
Returns a stream consisting of the elements of this stream in reverse sorted order.This is a stateful intermediate operation.
 Returns:
 the new stream
 Since:
 0.0.8

sortedBy
public <V extends Comparable<? super V>> IntStreamEx sortedBy(IntFunction<V> keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the natural order of the keys extracted by provided function.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
 Type Parameters:
V
 the type of theComparable
sort key Parameters:
keyExtractor
 a noninterfering , stateless function to be used to extract sorting keys Returns:
 the new stream

sortedByInt
public IntStreamEx sortedByInt(IntUnaryOperator keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the int values extracted by provided function.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
 Parameters:
keyExtractor
 a noninterfering , stateless function to be used to extract sorting keys Returns:
 the new stream

sortedByLong
public IntStreamEx sortedByLong(IntToLongFunction keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the long values extracted by provided function.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
 Parameters:
keyExtractor
 a noninterfering , stateless function to be used to extract sorting keys Returns:
 the new stream

sortedByDouble
public IntStreamEx sortedByDouble(IntToDoubleFunction keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the double values extracted by provided function.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
 Parameters:
keyExtractor
 a noninterfering , stateless function to be used to extract sorting keys Returns:
 the new stream

peek
public IntStreamEx peek(IntConsumer action)

peekFirst
public IntStreamEx peekFirst(IntConsumer action)
Returns a stream consisting of the elements of this stream, additionally performing the provided action on the first stream element when it's consumed from the resulting stream.This is an intermediate operation.
The action is called at most once. For parallel stream pipelines, it's not guaranteed in which thread it will be executed, so if it modifies shared state, it is responsible for providing the required synchronization.
Note that the action might not be called at all if the first element is not consumed from the input (for example, if there's shortcircuiting operation downstream which stopped the stream before the first element).
This method exists mainly to support debugging.
 Parameters:
action
 a noninterfering action to perform on the first stream element as it is consumed from the stream Returns:
 the new stream
 Since:
 0.6.0

peekLast
public IntStreamEx peekLast(IntConsumer action)
Returns a stream consisting of the elements of this stream, additionally performing the provided action on the last stream element when it's consumed from the resulting stream.This is an intermediate operation.
The action is called at most once. For parallel stream pipelines, it's not guaranteed in which thread it will be executed, so if it modifies shared state, it is responsible for providing the required synchronization.
Note that the action might not be called at all if the last element is not consumed from the input (for example, if there's shortcircuiting operation downstream).
This method exists mainly to support debugging.
 Parameters:
action
 a noninterfering action to perform on the first stream element as it is consumed from the stream Returns:
 the new stream
 Since:
 0.6.0

limit
public IntStreamEx limit(long maxSize)

skip
public IntStreamEx skip(long n)

forEach
public void forEach(IntConsumer action)

forEachOrdered
public void forEachOrdered(IntConsumer action)
 Specified by:
forEachOrdered
in interfaceIntStream

toByteArray
public byte[] toByteArray()
Returns abyte[]
array containing the elements of this stream which are converted to bytes using(byte)
cast operation.This is a terminal operation.
 Returns:
 an array containing the elements of this stream
 Since:
 0.3.0

toCharArray
public char[] toCharArray()
Returns achar[]
array containing the elements of this stream which are converted to chars using(char)
cast operation.This is a terminal operation.
 Returns:
 an array containing the elements of this stream
 Since:
 0.3.0

toShortArray
public short[] toShortArray()
Returns ashort[]
array containing the elements of this stream which are converted to shorts using(short)
cast operation.This is a terminal operation.
 Returns:
 an array containing the elements of this stream
 Since:
 0.3.0

toBitSet
public BitSet toBitSet()
Returns aBitSet
containing the elements of this stream.This is a terminal operation.
 Returns:
 a
BitSet
which set bits correspond to the elements of this stream.  Since:
 0.2.0

asByteInputStream
public InputStream asByteInputStream()
Returns anInputStream
lazily populated from the currentIntStreamEx
.Note that only the leastsignificant byte of every number encountered in this stream is preserved in the resulting
InputStream
, other bytes are silently lost. Thus it's a caller responsibility to check whether this may cause problems.This is a terminal operation.
When the resulting
InputStream
is closed, thisIntStreamEx
is closed as well. Returns:
 a new
InputStream
.  Since:
 0.6.1
 See Also:
of(InputStream)

reduce
public int reduce(int identity, IntBinaryOperator op)

reduce
public OptionalInt reduce(IntBinaryOperator op)

foldLeft
public OptionalInt foldLeft(IntBinaryOperator accumulator)
Folds the elements of this stream using the provided accumulation function, going left to right. This is equivalent to:boolean foundAny = false; int result = 0; for (int element : this stream) { if (!foundAny) { foundAny = true; result = element; } else result = accumulator.apply(result, element); } return foundAny ? OptionalInt.of(result) : OptionalInt.empty();
This is a terminal operation.
This method cannot take all the advantages of parallel streams as it must process elements strictly left to right. If your accumulator function is associative, consider using
reduce(IntBinaryOperator)
method.For parallel stream it's not guaranteed that accumulator will always be executed in the same thread.
 Parameters:
accumulator
 a noninterfering , stateless function for incorporating an additional element into a result Returns:
 the result of the folding
 Since:
 0.4.0
 See Also:
foldLeft(int, IntBinaryOperator)
,reduce(IntBinaryOperator)

foldLeft
public int foldLeft(int seed, IntBinaryOperator accumulator)
Folds the elements of this stream using the provided seed object and accumulation function, going left to right. This is equivalent to:int result = seed; for (int element : this stream) result = accumulator.apply(result, element) return result;
This is a terminal operation.
This method cannot take all the advantages of parallel streams as it must process elements strictly left to right. If your accumulator function is associative, consider using
reduce(int, IntBinaryOperator)
method.For parallel stream it's not guaranteed that accumulator will always be executed in the same thread.
 Parameters:
seed
 the starting valueaccumulator
 a noninterfering , stateless function for incorporating an additional element into a result Returns:
 the result of the folding
 Since:
 0.4.0
 See Also:
reduce(int, IntBinaryOperator)
,foldLeft(IntBinaryOperator)

scanLeft
public int[] scanLeft(IntBinaryOperator accumulator)
Produces an array containing cumulative results of applying the accumulation function going left to right.This is a terminal operation.
For parallel stream it's not guaranteed that accumulator will always be executed in the same thread.
This method cannot take all the advantages of parallel streams as it must process elements strictly left to right.
 Parameters:
accumulator
 a noninterfering , stateless function for incorporating an additional element into a result Returns:
 the array where the first element is the first element of this stream and every successor element is the result of applying accumulator function to the previous array element and the corresponding stream element. The resulting array has the same length as this stream.
 Since:
 0.5.1
 See Also:
foldLeft(IntBinaryOperator)

scanLeft
public int[] scanLeft(int seed, IntBinaryOperator accumulator)
Produces an array containing cumulative results of applying the accumulation function going left to right using given seed value.This is a terminal operation.
For parallel stream it's not guaranteed that accumulator will always be executed in the same thread.
This method cannot take all the advantages of parallel streams as it must process elements strictly left to right.
 Parameters:
seed
 the starting valueaccumulator
 a noninterfering , stateless function for incorporating an additional element into a result Returns:
 the array where the first element is the seed and every successor element is the result of applying accumulator function to the previous array element and the corresponding stream element. The resulting array is one element longer than this stream.
 Since:
 0.5.1
 See Also:
foldLeft(int, IntBinaryOperator)

collect
public <R> R collect(Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R,R> combiner)
 Specified by:
collect
in interfaceIntStream
 See Also:
collect(IntCollector)

collect
public <A,R> R collect(IntCollector<A,R> collector)
Performs a mutable reduction operation on the elements of this stream using anIntCollector
which encapsulates the supplier, accumulator and merger functions making easier to reuse collection strategies.Like
reduce(int, IntBinaryOperator)
,collect
operations can be parallelized without requiring additional synchronization.This is a terminal operation.
 Type Parameters:
A
 the intermediate accumulation type of theIntCollector
R
 type of the result Parameters:
collector
 theIntCollector
describing the reduction Returns:
 the result of the reduction
 Since:
 0.3.0
 See Also:
collect(Supplier, ObjIntConsumer, BiConsumer)

min
public OptionalInt min()

min
public OptionalInt min(Comparator<Integer> comparator)
Returns the minimum element of this stream according to the providedComparator
.This is a terminal operation.
 Parameters:
comparator
 a noninterfering, statelessComparator
to compare elements of this stream Returns:
 an
OptionalInt
describing the minimum element of this stream, or an emptyOptionalInt
if the stream is empty  Since:
 0.1.2

minBy
public <V extends Comparable<? super V>> OptionalInt minBy(IntFunction<V> keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.This is a terminal operation.
 Type Parameters:
V
 the type of theComparable
sort key Parameters:
keyExtractor
 a noninterfering, stateless function Returns:
 an
OptionalInt
describing some element of this stream for which the lowest value was returned by key extractor, or an emptyOptionalInt
if the stream is empty  Since:
 0.1.2

minByInt
public OptionalInt minByInt(IntUnaryOperator keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.This is a terminal operation.
 Parameters:
keyExtractor
 a noninterfering, stateless function Returns:
 an
OptionalInt
describing the first element of this stream for which the lowest value was returned by key extractor, or an emptyOptionalInt
if the stream is empty  Since:
 0.1.2

minByLong
public OptionalInt minByLong(IntToLongFunction keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.This is a terminal operation.
 Parameters:
keyExtractor
 a noninterfering, stateless function Returns:
 an
OptionalInt
describing some element of this stream for which the lowest value was returned by key extractor, or an emptyOptionalInt
if the stream is empty  Since:
 0.1.2

minByDouble
public OptionalInt minByDouble(IntToDoubleFunction keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.This is a terminal operation.
 Parameters:
keyExtractor
 a noninterfering, stateless function Returns:
 an
OptionalInt
describing some element of this stream for which the lowest value was returned by key extractor, or an emptyOptionalInt
if the stream is empty  Since:
 0.1.2

max
public OptionalInt max()

max
public OptionalInt max(Comparator<Integer> comparator)
Returns the maximum element of this stream according to the providedComparator
.This is a terminal operation.
 Parameters:
comparator
 a noninterfering, statelessComparator
to compare elements of this stream Returns:
 an
OptionalInt
describing the maximum element of this stream, or an emptyOptionalInt
if the stream is empty

maxBy
public <V extends Comparable<? super V>> OptionalInt maxBy(IntFunction<V> keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.This is a terminal operation.
 Type Parameters:
V
 the type of theComparable
sort key Parameters:
keyExtractor
 a noninterfering, stateless function Returns:
 an
OptionalInt
describing the first element of this stream for which the highest value was returned by key extractor, or an emptyOptionalInt
if the stream is empty  Since:
 0.1.2

maxByInt
public OptionalInt maxByInt(IntUnaryOperator keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.This is a terminal operation.
 Parameters:
keyExtractor
 a noninterfering, stateless function Returns:
 an
OptionalInt
describing the first element of this stream for which the highest value was returned by key extractor, or an emptyOptionalInt
if the stream is empty  Since:
 0.1.2

maxByLong
public OptionalInt maxByLong(IntToLongFunction keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.This is a terminal operation.
 Parameters:
keyExtractor
 a noninterfering, stateless function Returns:
 an
OptionalInt
describing the first element of this stream for which the highest value was returned by key extractor, or an emptyOptionalInt
if the stream is empty  Since:
 0.1.2

maxByDouble
public OptionalInt maxByDouble(IntToDoubleFunction keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.This is a terminal operation.
 Parameters:
keyExtractor
 a noninterfering, stateless function Returns:
 an
OptionalInt
describing the first element of this stream for which the highest value was returned by key extractor, or an emptyOptionalInt
if the stream is empty  Since:
 0.1.2

average
public OptionalDouble average()

summaryStatistics
public IntSummaryStatistics summaryStatistics()
 Specified by:
summaryStatistics
in interfaceIntStream

anyMatch
public boolean anyMatch(IntPredicate predicate)

allMatch
public boolean allMatch(IntPredicate predicate)

noneMatch
public boolean noneMatch(IntPredicate predicate)

findFirst
public OptionalInt findFirst()

findFirst
public OptionalInt findFirst(IntPredicate predicate)
Returns anOptionalInt
describing the first element of this stream, which matches given predicate, or an emptyOptionalInt
if there's no matching element.This is a shortcircuiting terminal operation.
 Parameters:
predicate
 a noninterfering , stateless predicate which returned value should match Returns:
 an
OptionalInt
describing the first matching element of this stream, or an emptyOptionalInt
if there's no matching element  See Also:
findFirst()

findAny
public OptionalInt findAny()

findAny
public OptionalInt findAny(IntPredicate predicate)
Returns anOptionalInt
describing some element of the stream, which matches given predicate, or an emptyOptionalInt
if there's no matching element.This is a shortcircuiting terminal operation.
The behavior of this operation is explicitly nondeterministic; it is free to select any element in the stream. This is to allow for maximal performance in parallel operations; the cost is that multiple invocations on the same source may not return the same result. (If a stable result is desired, use
findFirst(IntPredicate)
instead.) Parameters:
predicate
 a noninterfering , stateless predicate which returned value should match Returns:
 an
OptionalInt
describing some matching element of this stream, or an emptyOptionalInt
if there's no matching element  See Also:
findAny()
,findFirst(IntPredicate)

indexOf
public OptionalLong indexOf(int value)
Returns anOptionalLong
describing the zerobased index of the first element of this stream, which equals to the given value, or an emptyOptionalLong
if there's no matching element.This is a shortcircuiting terminal operation.
 Parameters:
value
 a value to look for Returns:
 an
OptionalLong
describing the index of the first matching element of this stream, or an emptyOptionalLong
if there's no matching element.  Since:
 0.4.0
 See Also:
indexOf(IntPredicate)

indexOf
public OptionalLong indexOf(IntPredicate predicate)
Returns anOptionalLong
describing the zerobased index of the first element of this stream, which matches given predicate, or an emptyOptionalLong
if there's no matching element.This is a shortcircuiting terminal operation.
 Parameters:
predicate
 a noninterfering , stateless predicate which returned value should match Returns:
 an
OptionalLong
describing the index of the first matching element of this stream, or an emptyOptionalLong
if there's no matching element.  Since:
 0.4.0
 See Also:
findFirst(IntPredicate)

asLongStream
public LongStreamEx asLongStream()
 Specified by:
asLongStream
in interfaceIntStream

asDoubleStream
public DoubleStreamEx asDoubleStream()
 Specified by:
asDoubleStream
in interfaceIntStream

sequential
public IntStreamEx sequential()
 Specified by:
sequential
in interfaceBaseStream<Integer,IntStream>
 Specified by:
sequential
in interfaceIntStream

parallel
public IntStreamEx parallel()
If this stream was created using
parallel(ForkJoinPool)
, the new stream forgets about supplied customForkJoinPool
and its terminal operation will be executed in common pool.

parallel
public IntStreamEx parallel(ForkJoinPool fjp)
Returns an equivalent stream that is parallel and bound to the suppliedForkJoinPool
.This is an intermediate operation.
The terminal operation of this stream or any derived stream (except the streams created via
BaseStream.parallel()
orBaseStream.sequential()
methods) will be executed inside the suppliedForkJoinPool
. If current thread does not belong to that pool, it will wait till calculation finishes. Parameters:
fjp
 aForkJoinPool
to submit the stream operation to. Returns:
 a parallel stream bound to the supplied
ForkJoinPool

iterator
public PrimitiveIterator.OfInt iterator()

append
public IntStreamEx append(int... values)
Returns a newIntStreamEx
which is a concatenation of this stream and the stream containing supplied valuesThis is a quasiintermediate operation.
 Parameters:
values
 the values to append to the stream Returns:
 the new stream

append
public IntStreamEx append(IntStream other)
Creates a lazily concatenated stream whose elements are all the elements of this stream followed by all the elements of the other stream. The resulting stream is ordered if both of the input streams are ordered, and parallel if either of the input streams is parallel. When the resulting stream is closed, the close handlers for both input streams are invoked. Parameters:
other
 the other stream Returns:
 this stream appended by the other stream
 See Also:
IntStream.concat(IntStream, IntStream)

prepend
public IntStreamEx prepend(int... values)
Returns a newIntStreamEx
which is a concatenation of the stream containing supplied values and this streamThis is a quasiintermediate operation.
 Parameters:
values
 the values to prepend to the stream Returns:
 the new stream

prepend
public IntStreamEx prepend(IntStream other)
Creates a lazily concatenated stream whose elements are all the elements of the other stream followed by all the elements of this stream. The resulting stream is ordered if both of the input streams are ordered, and parallel if either of the input streams is parallel. When the resulting stream is closed, the close handlers for both input streams are invoked. Parameters:
other
 the other stream Returns:
 this stream prepended by the other stream
 See Also:
IntStream.concat(IntStream, IntStream)

elements
public <U> StreamEx<U> elements(U[] array)
Returns an objectvaluedStreamEx
consisting of the elements of given array corresponding to the indices which appear in this stream.This is an intermediate operation.
 Type Parameters:
U
 the element type of the new stream Parameters:
array
 the array to take the elements from Returns:
 the new stream
 Since:
 0.1.2

elements
public <U> StreamEx<U> elements(List<U> list)
Returns an objectvaluedStreamEx
consisting of the elements of givenList
corresponding to the indices which appear in this stream.The list elements are accessed using
List.get(int)
, so the list should provide fast random access. The list is assumed to be unmodifiable during the stream operations.This is an intermediate operation.
 Type Parameters:
U
 the element type of the new stream Parameters:
list
 the list to take the elements from Returns:
 the new stream
 Since:
 0.1.2

elements
public IntStreamEx elements(int[] array)
Returns anIntStreamEx
consisting of the elements of given array corresponding to the indices which appear in this stream.This is an intermediate operation.
 Parameters:
array
 the array to take the elements from Returns:
 the new stream
 Since:
 0.1.2

elements
public LongStreamEx elements(long[] array)
Returns aLongStreamEx
consisting of the elements of given array corresponding to the indices which appear in this stream.This is an intermediate operation.
 Parameters:
array
 the array to take the elements from Returns:
 the new stream
 Since:
 0.1.2

elements
public DoubleStreamEx elements(double[] array)
Returns aDoubleStreamEx
consisting of the elements of given array corresponding to the indices which appear in this stream.This is an intermediate operation.
 Parameters:
array
 the array to take the elements from Returns:
 the new stream
 Since:
 0.1.2

charsToString
public String charsToString()
Returns aString
consisting of chars from this stream.This is a terminal operation.
During string creation stream elements are converted to chars using
(char)
cast operation. Returns:
 a new
String
 Since:
 0.2.1

codePointsToString
public String codePointsToString()
Returns aString
consisting of code points from this stream.This is a terminal operation.
 Returns:
 a new
String
 Since:
 0.2.1

pairMap
public IntStreamEx pairMap(IntBinaryOperator mapper)
Returns a stream consisting of the results of applying the given function to the every adjacent pair of elements of this stream.This is a quasiintermediate operation.
The output stream will contain one element less than this stream. If this stream contains zero or one element the output stream will be empty.
 Parameters:
mapper
 a noninterfering, stateless function to apply to each adjacent pair of this stream elements. Returns:
 the new stream
 Since:
 0.2.1

joining
public String joining(CharSequence delimiter)
Returns aString
which is the concatenation of the results of callingString.valueOf(int)
on each element of this stream, separated by the specified delimiter, in encounter order.This is a terminal operation.
 Parameters:
delimiter
 the delimiter to be used between each element Returns:
 the result of concatenation. For empty input stream empty String is returned.
 Since:
 0.3.1

joining
public String joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
Returns aString
which is the concatenation of the results of callingString.valueOf(int)
on each element of this stream, separated by the specified delimiter, with the specified prefix and suffix in encounter order.This is a terminal operation.
 Parameters:
delimiter
 the delimiter to be used between each elementprefix
 the sequence of characters to be used at the beginning of the joined resultsuffix
 the sequence of characters to be used at the end of the joined result Returns:
 the result of concatenation. For empty input stream
prefix + suffix
is returned.  Since:
 0.3.1

takeWhile
public IntStreamEx takeWhile(IntPredicate predicate)
Returns a stream consisting of all elements from this stream until the first element which does not match the given predicate is found.This is a shortcircuiting stateful operation. It can be either intermediate or quasiintermediate. When using with JDK 1.9 or higher it calls the corresponding JDK 1.9 implementation. When using with JDK 1.8 it uses own implementation.
While this operation is quite cheap for sequential stream, it can be quite expensive on parallel pipelines.
 Specified by:
takeWhile
in interfaceIntStream
 Parameters:
predicate
 a noninterfering, stateless predicate to apply to elements. Returns:
 the new stream.
 Since:
 0.3.6
 See Also:
takeWhileInclusive(IntPredicate)
,dropWhile(IntPredicate)

takeWhileInclusive
public IntStreamEx takeWhileInclusive(IntPredicate predicate)
Returns a stream consisting of all elements from this stream until the first element which does not match the given predicate is found (including the first mismatching element).This is a quasiintermediate operation.
While this operation is quite cheap for sequential stream, it can be quite expensive on parallel pipelines.
 Parameters:
predicate
 a noninterfering, stateless predicate to apply to elements. Returns:
 the new stream.
 Since:
 0.5.5
 See Also:
takeWhile(IntPredicate)

dropWhile
public IntStreamEx dropWhile(IntPredicate predicate)
Returns a stream consisting of all elements from this stream starting from the first element which does not match the given predicate. If the predicate is true for all stream elements, an empty stream is returned.This is a stateful operation. It can be either intermediate or quasiintermediate. When using with JDK 1.9 or higher it calls the corresponding JDK 1.9 implementation. When using with JDK 1.8 it uses own implementation.
While this operation is quite cheap for sequential stream, it can be quite expensive on parallel pipelines.

mapFirst
public IntStreamEx mapFirst(IntUnaryOperator mapper)
Returns a stream where the first element is the replaced with the result of applying the given function while the other elements are left intact.This is a quasiintermediate operation.
 Parameters:
mapper
 a noninterfering , stateless function to apply to the first element Returns:
 the new stream
 Since:
 0.4.1

mapLast
public IntStreamEx mapLast(IntUnaryOperator mapper)
Returns a stream where the last element is the replaced with the result of applying the given function while the other elements are left intact.This is a quasiintermediate operation.
The mapper function is called at most once. It could be not called at all if the stream is empty or there is shortcircuiting operation downstream.
 Parameters:
mapper
 a noninterfering , stateless function to apply to the last element Returns:
 the new stream
 Since:
 0.4.1

prefix
public IntStreamEx prefix(IntBinaryOperator op)
Returns a stream containing cumulative results of applying the accumulation function going left to right.This is a stateful quasiintermediate operation.
This operation resembles
scanLeft(IntBinaryOperator)
, but unlikescanLeft
this operation is intermediate and accumulation function must be associative.This method cannot take all the advantages of parallel streams as it must process elements strictly left to right. Using an unordered source or removing the ordering constraint with
unordered()
may improve the parallel processing speed. Parameters:
op
 an associative , noninterfering , stateless function for computing the next element based on the previous one Returns:
 the new stream.
 Since:
 0.6.1
 See Also:
scanLeft(IntBinaryOperator)

chain
public <U> U chain(Function<? super IntStreamEx,U> mapper)
Applies the supplied function to this stream and returns the result of the function.This method can be used to add more functionality in the fluent style. For example, consider userdefined static method
batches(stream, n)
which breaks the stream into batches of given length. Normally you would writebatches(StreamEx.of(input).map(...), 10).filter(...)
. Using thechain()
method you can write in more fluent manner:StreamEx.of(input).map(...).chain(s > batches(s, 10)).filter(...)
.You could even go further and define a method which returns a function like
<T> UnaryOperator<StreamEx<T>> batches(int n)
and use it like this:StreamEx.of(input).map(...).chain(batches(10)).filter(...)
. Type Parameters:
U
 the type of the function result. Parameters:
mapper
 function to invoke. Returns:
 the result of the function invocation.

empty
public static IntStreamEx empty()
Returns an empty sequentialIntStreamEx
. Returns:
 an empty sequential stream

of
public static IntStreamEx of(int element)
Returns a sequentialIntStreamEx
containing a single element. Parameters:
element
 the single element Returns:
 a singleton sequential stream

of
public static IntStreamEx of(int... elements)
Returns a sequential orderedIntStreamEx
whose elements are the specified values. Parameters:
elements
 the elements of the new stream Returns:
 the new stream

of
public static IntStreamEx of(int[] array, int startInclusive, int endExclusive)
Returns a sequentialIntStreamEx
with the specified range of the specified array as its source. Parameters:
array
 the array, assumed to be unmodified during usestartInclusive
 the first index to cover, inclusiveendExclusive
 index immediately past the last index to cover Returns:
 an
IntStreamEx
for the array range  Throws:
ArrayIndexOutOfBoundsException
 ifstartInclusive
is negative,endExclusive
is less thanstartInclusive
, orendExclusive
is greater than the array size Since:
 0.1.1
 See Also:
Arrays.stream(int[], int, int)

of
public static IntStreamEx of(byte... elements)
Returns a sequential orderedIntStreamEx
whose elements are the specified values casted to int. Parameters:
elements
 the elements of the new stream Returns:
 the new stream
 Since:
 0.2.0

of
public static IntStreamEx of(byte[] array, int startInclusive, int endExclusive)
Returns a sequentialIntStreamEx
with the specified range of the specified array as its source. Array values will be casted to int. Parameters:
array
 the array, assumed to be unmodified during usestartInclusive
 the first index to cover, inclusiveendExclusive
 index immediately past the last index to cover Returns:
 an
IntStreamEx
for the array range  Throws:
ArrayIndexOutOfBoundsException
 ifstartInclusive
is negative,endExclusive
is less thanstartInclusive
, orendExclusive
is greater than the array size Since:
 0.2.0

of
public static IntStreamEx of(char... elements)
Returns a sequential orderedIntStreamEx
whose elements are the specified values casted to int. Parameters:
elements
 the elements of the new stream Returns:
 the new stream
 Since:
 0.2.0

of
public static IntStreamEx of(char[] array, int startInclusive, int endExclusive)
Returns a sequentialIntStreamEx
with the specified range of the specified array as its source. Array values will be casted to int. Parameters:
array
 the array, assumed to be unmodified during usestartInclusive
 the first index to cover, inclusiveendExclusive
 index immediately past the last index to cover Returns:
 an
IntStreamEx
for the array range  Throws:
ArrayIndexOutOfBoundsException
 ifstartInclusive
is negative,endExclusive
is less thanstartInclusive
, orendExclusive
is greater than the array size Since:
 0.2.0

of
public static IntStreamEx of(short... elements)
Returns a sequential orderedIntStreamEx
whose elements are the specified values casted to int. Parameters:
elements
 the elements of the new stream Returns:
 the new stream
 Since:
 0.2.0

of
public static IntStreamEx of(short[] array, int startInclusive, int endExclusive)
Returns a sequentialIntStreamEx
with the specified range of the specified array as its source. Array values will be casted to int. Parameters:
array
 the array, assumed to be unmodified during usestartInclusive
 the first index to cover, inclusiveendExclusive
 index immediately past the last index to cover Returns:
 an
IntStreamEx
for the array range  Throws:
ArrayIndexOutOfBoundsException
 ifstartInclusive
is negative,endExclusive
is less thanstartInclusive
, orendExclusive
is greater than the array size Since:
 0.2.0

of
public static IntStreamEx of(InputStream is)
Returns a sequential orderedIntStreamEx
backed by the content of givenInputStream
.The resulting stream contains int values between 0 and 255 (0xFF) inclusive, as they are returned by the
InputStream.read()
method. If you want to getbyte
values (e.g. 1 instead of 255), simply cast the stream elements like.map(b > (byte)b)
. The terminal 1 value is excluded from the resulting stream.If the underlying
InputStream
throws anIOException
during the stream traversal, it will be rethrown asUncheckedIOException
.When the returned
IntStreamEx
is closed the originalInputStream
is closed as well. IfInputStream.close()
method throws anIOException
, it will be rethrown asUncheckedIOException
. Parameters:
is
 anInputStream
to create anIntStreamEx
on. Returns:
 the new stream
 Since:
 0.6.1
 See Also:
asByteInputStream()

of
public static IntStreamEx of(Integer[] array)
Returns a sequential orderedIntStreamEx
whose elements are the unboxed elements of supplied array. Parameters:
array
 the array to create the stream from. Returns:
 the new stream
 Since:
 0.5.0
 See Also:
Arrays.stream(Object[])

of
public static IntStreamEx of(IntBuffer buf)
Returns a sequential orderedIntStreamEx
whose elements are the values in the suppliedIntBuffer
.The resulting stream covers only a portion of
IntBuffer
content which starts with position (inclusive) and ends with limit (exclusive). Changes in position and limit after the stream creation don't affect the stream.The resulting stream does not change the internal
IntBuffer
state. Parameters:
buf
 theIntBuffer
to create a stream from Returns:
 the new stream
 Since:
 0.6.2

ofIndices
public static <T> IntStreamEx ofIndices(List<T> list)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied list. Type Parameters:
T
 list element type Parameters:
list
 list to get the stream of its indices Returns:
 a sequential
IntStreamEx
for the range ofint
elements starting from 0 to (not inclusive) list.size()  Since:
 0.1.1

ofIndices
public static <T> IntStreamEx ofIndices(List<T> list, Predicate<T> predicate)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied list elements which match given predicate.The list elements are accessed using
List.get(int)
, so the list should provide fast random access. The list is assumed to be unmodifiable during the stream operations. Type Parameters:
T
 list element type Parameters:
list
 list to get the stream of its indicespredicate
 a predicate to test list elements Returns:
 a sequential
IntStreamEx
of the matched list indices  Since:
 0.1.1

ofIndices
public static <T> IntStreamEx ofIndices(T[] array)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied array. Type Parameters:
T
 array element type Parameters:
array
 array to get the stream of its indices Returns:
 a sequential
IntStreamEx
for the range ofint
elements starting from 0 to (not inclusive) array.length  Since:
 0.1.1

ofIndices
public static <T> IntStreamEx ofIndices(T[] array, Predicate<T> predicate)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied array elements which match given predicate. Type Parameters:
T
 array element type Parameters:
array
 array to get the stream of its indicespredicate
 a predicate to test array elements Returns:
 a sequential
IntStreamEx
of the matched array indices  Since:
 0.1.1

ofIndices
public static IntStreamEx ofIndices(int[] array)
Returns a sequential orderedIntStreamEx
containing all the indices of supplied array. Parameters:
array
 array to get the stream of its indices Returns:
 a sequential
IntStreamEx
for the range ofint
elements starting from 0 to (not inclusive) array.length  Since:
 0.1.1

ofIndices
public static IntStreamEx ofIndices(int[] array, IntPredicate predicate)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied array elements which match given predicate. Parameters:
array
 array to get the stream of its indicespredicate
 a predicate to test array elements Returns:
 a sequential
IntStreamEx
of the matched array indices  Since:
 0.1.1

ofIndices
public static IntStreamEx ofIndices(long[] array)
Returns a sequential orderedIntStreamEx
containing all the indices of supplied array. Parameters:
array
 array to get the stream of its indices Returns:
 a sequential
IntStreamEx
for the range ofint
elements starting from 0 to (not inclusive) array.length  Since:
 0.1.1

ofIndices
public static IntStreamEx ofIndices(long[] array, LongPredicate predicate)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied array elements which match given predicate. Parameters:
array
 array to get the stream of its indicespredicate
 a predicate to test array elements Returns:
 a sequential
IntStreamEx
of the matched array indices  Since:
 0.1.1

ofIndices
public static IntStreamEx ofIndices(double[] array)
Returns a sequential orderedIntStreamEx
containing all the indices of supplied array. Parameters:
array
 array to get the stream of its indices Returns:
 a sequential
IntStreamEx
for the range ofint
elements starting from 0 to (not inclusive) array.length  Since:
 0.1.1

ofIndices
public static IntStreamEx ofIndices(double[] array, DoublePredicate predicate)
Returns a sequential orderedIntStreamEx
containing all the indices of the supplied array elements which match given predicate. Parameters:
array
 array to get the stream of its indicespredicate
 a predicate to test array elements Returns:
 a sequential
IntStreamEx
of the matched array indices  Since:
 0.1.1

of
public static IntStreamEx of(IntStream stream)
Returns anIntStreamEx
object which wraps givenIntStream
.The supplied stream must not be consumed or closed when this method is called. No operation must be performed on the supplied stream after it's wrapped.
 Parameters:
stream
 original stream Returns:
 the wrapped stream
 Since:
 0.0.8

of
public static IntStreamEx of(Spliterator.OfInt spliterator)
Returns a sequentialIntStreamEx
created from givenSpliterator.OfInt
. Parameters:
spliterator
 a spliterator to create the stream from. Returns:
 the new stream
 Since:
 0.3.4

of
public static IntStreamEx of(PrimitiveIterator.OfInt iterator)
Returns a sequential, orderedIntStreamEx
created from givenPrimitiveIterator.OfInt
.This method is roughly equivalent to
IntStreamEx.of(Spliterators.spliteratorUnknownSize(iterator, ORDERED))
, but may show better performance for parallel processing.Use this method only if you cannot provide better Stream source.
 Parameters:
iterator
 an iterator to create the stream from. Returns:
 the new stream
 Since:
 0.5.1

of
public static IntStreamEx of(OptionalInt optional)
Returns a sequentialIntStreamEx
containing anOptionalInt
value, if present, otherwise returns an emptyIntStreamEx
. Parameters:
optional
 the optional to create a stream of Returns:
 a stream with an
OptionalInt
value if present, otherwise an empty stream  Since:
 0.1.1

of
public static IntStreamEx of(BitSet bitSet)
Returns anIntStreamEx
of indices for which the specifiedBitSet
contains a bit in the set state. The indices are returned in order, from lowest to highest. The size of the stream is the number of bits in the set state, equal to the value returned by theBitSet.cardinality()
method.The bit set must remain constant during the execution of the terminal stream operation. Otherwise, the result of the terminal stream operation is undefined.
 Parameters:
bitSet
 aBitSet
to produce the stream from Returns:
 a stream of integers representing set indices
 See Also:
BitSet.stream()

of
public static IntStreamEx of(Collection<Integer> collection)
Returns a sequential orderedIntStreamEx
whose elements are the unboxed elements of supplied collection. Parameters:
collection
 the collection to create the stream from. Returns:
 the new stream
 See Also:
Collection.stream()

of
public static IntStreamEx of(Random random)
Returns an effectively unlimited stream of pseudorandomint
values produced by givenRandom
object.A pseudorandom
int
value is generated as if it's the result of calling the methodRandom.nextInt()
. Parameters:
random
 aRandom
object to produce the stream from Returns:
 a stream of pseudorandom
int
values  See Also:
Random.ints()

of
public static IntStreamEx of(Random random, long streamSize)
Returns a stream producing the givenstreamSize
number of pseudorandomint
values.A pseudorandom
int
value is generated as if it's the result of calling the methodRandom.nextInt()
. Parameters:
random
 aRandom
object to produce the stream fromstreamSize
 the number of values to generate Returns:
 a stream of pseudorandom
int
values  See Also:
Random.ints(long)

of
public static IntStreamEx of(Random random, int randomNumberOrigin, int randomNumberBound)
Returns an effectively unlimited stream of pseudorandomint
values, each conforming to the given origin (inclusive) and bound (exclusive). Parameters:
random
 aRandom
object to produce the stream fromrandomNumberOrigin
 the origin (inclusive) of each random valuerandomNumberBound
 the bound (exclusive) of each random value Returns:
 a stream of pseudorandom
int
values  See Also:
Random.ints(long, int, int)

of
public static IntStreamEx of(Random random, long streamSize, int randomNumberOrigin, int randomNumberBound)
Returns a stream producing the givenstreamSize
number of pseudorandomint
values, each conforming to the given origin (inclusive) and bound (exclusive). Parameters:
random
 aRandom
object to produce the stream fromstreamSize
 the number of values to generaterandomNumberOrigin
 the origin (inclusive) of each random valuerandomNumberBound
 the bound (exclusive) of each random value Returns:
 a stream of pseudorandom
int
values  See Also:
Random.ints(long, int, int)

ofChars
public static IntStreamEx ofChars(CharSequence seq)
Returns anIntStreamEx
ofint
zeroextending thechar
values from the suppliedCharSequence
. Any char which maps to a surrogate code point is passed through uninterpreted.If the sequence is mutated while the stream is being read, the result is undefined.
 Parameters:
seq
 sequence to read characters from Returns:
 an IntStreamEx of char values from the sequence
 See Also:
CharSequence.chars()

ofCodePoints
public static IntStreamEx ofCodePoints(CharSequence seq)
Returns anIntStreamEx
of code point values from the suppliedCharSequence
. Any surrogate pairs encountered in the sequence are combined as if by Character.toCodePoint and the result is passed to the stream. Any other code units, including ordinary BMP characters, unpaired surrogates, and undefined code units, are zeroextended toint
values which are then passed to the stream.If the sequence is mutated while the stream is being read, the result is undefined.
 Parameters:
seq
 sequence to read code points from Returns:
 an IntStreamEx of Unicode code points from this sequence
 See Also:
CharSequence.codePoints()

iterate
public static IntStreamEx iterate(int seed, IntUnaryOperator f)
Returns an infinite sequential orderedIntStreamEx
produced by iterative application of a functionf
to an initial elementseed
, producing a stream consisting ofseed
,f(seed)
,f(f(seed))
, etc.The first element (position
0
) in theIntStreamEx
will be the providedseed
. Forn > 0
, the element at positionn
, will be the result of applying the functionf
to the element at positionn  1
. Parameters:
seed
 the initial elementf
 a function to be applied to to the previous element to produce a new element Returns:
 A new sequential
IntStream
 See Also:
iterate(int, IntPredicate, IntUnaryOperator)

iterate
public static IntStreamEx iterate(int seed, IntPredicate predicate, IntUnaryOperator f)
Returns a sequential orderedIntStreamEx
produced by iterative application of a function to an initial element, conditioned on satisfying the supplied predicate. The stream terminates as soon as the predicate function returns false.IntStreamEx.iterate
should produce the same sequence of elements as produced by the corresponding forloop:for (int index=seed; predicate.test(index); index = f.apply(index)) { ... }
The resulting sequence may be empty if the predicate does not hold on the seed value. Otherwise the first element will be the supplied seed value, the next element (if present) will be the result of applying the function f to the seed value, and so on iteratively until the predicate indicates that the stream should terminate.
 Parameters:
seed
 the initial elementpredicate
 a predicate to apply to elements to determine when the stream must terminate.f
 a function to be applied to the previous element to produce a new element Returns:
 a new sequential
IntStreamEx
 Since:
 0.6.0
 See Also:
iterate(int, IntUnaryOperator)

generate
public static IntStreamEx generate(IntSupplier s)
Returns an infinite sequential unordered stream where each element is generated by the providedIntSupplier
. This is suitable for generating constant streams, streams of random elements, etc. Parameters:
s
 theIntSupplier
for generated elements Returns:
 a new infinite sequential unordered
IntStreamEx
 See Also:
IntStream.generate(IntSupplier)

produce
public static IntStreamEx produce(Predicate<IntConsumer> producer)
Return an ordered stream produced by consecutive calls of the supplied producer until it returns false.The producer function may call the passed consumer any number of times and return true if the producer should be called again or false otherwise. It's guaranteed that the producer will not be called anymore, once it returns false.
This method is particularly useful when producer changes the mutable object which should be left in known state after the full stream consumption. Note however that if a shortcircuiting operation is used, then the final state of the mutable object cannot be guaranteed.
 Parameters:
producer
 a predicate which calls the passed consumer to emit stream element(s) and returns true if it producer should be applied again. Returns:
 the new stream
 Since:
 0.6.0

ints
public static IntStreamEx ints()
Returns a sequential orderedIntStreamEx
from 0 (inclusive) toInteger.MAX_VALUE
(exclusive) by an incremental step of1
. Returns:
 a sequential
IntStreamEx
for the range ofint
elements  Since:
 0.5.5
 See Also:
range(int, int)

range
public static IntStreamEx range(int endExclusive)
Returns a sequential orderedIntStreamEx
from 0 (inclusive) toendExclusive
(exclusive) by an incremental step of1
. Parameters:
endExclusive
 the exclusive upper bound Returns:
 a sequential
IntStreamEx
for the range ofint
elements  Since:
 0.1.1
 See Also:
range(int, int)

range
public static IntStreamEx range(int startInclusive, int endExclusive)
Returns a sequential orderedIntStreamEx
fromstartInclusive
(inclusive) toendExclusive
(exclusive) by an incremental step of1
. Parameters:
startInclusive
 the (inclusive) initial valueendExclusive
 the exclusive upper bound Returns:
 a sequential
IntStreamEx
for the range ofint
elements  See Also:
IntStream.range(int, int)

range
public static IntStreamEx range(int startInclusive, int endExclusive, int step)
Returns a sequential orderedIntStreamEx
fromstartInclusive
(inclusive) toendExclusive
(exclusive) by the specified incremental step. The negative step values are also supported. In this case, thestartInclusive
should be greater thanendExclusive
. Parameters:
startInclusive
 the (inclusive) initial valueendExclusive
 the exclusive upper (for positive step) or lower (for negative step) boundstep
 the nonzero value which designates the difference between the consecutive values of the resulting stream. Returns:
 a sequential
IntStreamEx
for the range ofint
elements  Throws:
IllegalArgumentException
 if step is zero Since:
 0.4.0
 See Also:
range(int, int)

rangeClosed
public static IntStreamEx rangeClosed(int startInclusive, int endInclusive)
Returns a sequential orderedIntStreamEx
fromstartInclusive
(inclusive) toendInclusive
(inclusive) by an incremental step of1
. Parameters:
startInclusive
 the (inclusive) initial valueendInclusive
 the inclusive upper bound Returns:
 a sequential
IntStreamEx
for the range ofint
elements  See Also:
IntStream.rangeClosed(int, int)

rangeClosed
public static IntStreamEx rangeClosed(int startInclusive, int endInclusive, int step)
Returns a sequential orderedIntStreamEx
fromstartInclusive
(inclusive) toendInclusive
(inclusive) by the specified incremental step. The negative step values are also supported. In this case, thestartInclusive
should be not less thanendInclusive
.Note that depending on the step value the
endInclusive
bound may still not be reached. For exampleIntStreamEx.rangeClosed(0, 5, 2)
will yield the stream of three numbers: 0, 2 and 4. Parameters:
startInclusive
 the (inclusive) initial valueendInclusive
 the inclusive upper (for positive step) or lower (for negative step) boundstep
 the nonzero value which designates the difference between the consecutive values of the resulting stream. Returns:
 a sequential
IntStreamEx
for the range ofint
elements; an empty stream if startInclusive is greater than endInclusive for positive step, or if startInclusive is less than endInclusive for negative step.  Throws:
IllegalArgumentException
 if step is zero Since:
 0.4.0
 See Also:
rangeClosed(int, int)

constant
public static IntStreamEx constant(int value, long length)
Returns a sequential unorderedIntStreamEx
of given length which elements are equal to supplied value. Parameters:
value
 the constant valuelength
 the length of the stream Returns:
 a new
IntStreamEx
 Since:
 0.1.2

zip
public static IntStreamEx zip(int[] first, int[] second, IntBinaryOperator mapper)
Returns a sequentialIntStreamEx
containing the results of applying the given function to the corresponding pairs of values in given two arrays. Parameters:
first
 the first arraysecond
 the second arraymapper
 a noninterfering, stateless function to apply to each pair of the corresponding array elements. Returns:
 a new
IntStreamEx
 Throws:
IllegalArgumentException
 if length of the arrays differs. Since:
 0.2.1

spliterator
public SPLTR spliterator()
 Specified by:
spliterator
in interfaceBaseStream<T,S extends BaseStream<T,S>>

isParallel
public boolean isParallel()
 Specified by:
isParallel
in interfaceBaseStream<T,S extends BaseStream<T,S>>

close
public void close()
 Specified by:
close
in interfaceAutoCloseable
 Specified by:
close
in interfaceBaseStream<T,S extends BaseStream<T,S>>

