![]() |
VOOZH | about |
IntStream of(int t) returns a sequential IntStream containing a single element.
Syntax :
static IntStream of(int t)
Parameters :
Return Value : IntStream of(int t) returns a sequential IntStream containing the single specified element.
Example :
Output :
-7
IntStream of(int... values) returns a sequential ordered stream whose elements are the specified values.
Syntax :
static IntStream of(int... values)
Parameters :
Return Value : IntStream of(int... values) returns a sequential ordered stream whose elements are the specified values.
Example 1 :
Output :
-7 -9 -11
Example 2 :
Output :
3
Example 3
Streams are not reusable if we have performed terminal operation on stream and try to reuse them again IllegalStateExeception will be generated
Output :
OptionalInt[10] java.lang.IllegalStateException: stream has already been operated upon or closed
To reuse a stream we need Supplier class when get() method of Supplier is called every time it will generate a new instance and return it.
Output :
1 61 343 434 512 561 5234 613434 434 512 5234 613434 613434 5234 512 434
Example 4
Finding min,max,sum and average from an IntStream
Output :
Average : 77572.5 Sum : 620580 min : 1 max : 613434
Example 5
Range based operation