IntStream of(int t)
IntStream of(int t) returns a sequential IntStream containing a single element.
Syntax :
static IntStream of(int t)
Parameters :
- IntStream : A sequence of primitive int-valued elements.
- t : Represents the single element in the IntStream.
Return Value : IntStream of(int t) returns a sequential IntStream containing the single specified element.
Example :
// Java code for IntStream of(int t) // to get a sequential IntStream // containing a single element. import java.util.*; import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // Creating an IntStream having single element only IntStream stream = IntStream.of(-7); // Displaying the IntStream having single element stream.forEach(System.out::println); } } |
Output :
-7
IntStream of(int… values)
IntStream of(int… values) returns a sequential ordered stream whose elements are the specified values.
Syntax :
static IntStream of(int... values)
Parameters :
- IntStream : A sequence of primitive int-valued elements.
- values : Represents the elements of the new stream.
Return Value : IntStream of(int… values) returns a sequential ordered stream whose elements are the specified values.
Example 1 :
// Java code for IntStream of(int... values) // to get a sequential ordered stream whose // elements are the specified values. import java.util.*; import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // Creating an IntStream IntStream stream = IntStream.of(-7, -9, -11); // Displaying the sequential ordered stream stream.forEach(System.out::println); } } |
Output :
-7 -9 -11
Example 2 :
// Java code for IntStream of(int... values) // to get a sequential ordered stream whose // elements are the specified values. import java.util.*; import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // Creating an IntStream IntStream stream = IntStream.of(-7, -9, -11); // Storing the count of elements in IntStream long total = stream.count(); // Displaying the count of elements System.out.println(total); } } |
Output :
3
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- java.util.stream.IntStream/LongStream | Search an element
- IntStream iterator() in Java
- IntStream rangeClosed() in Java
- IntStream map(IntUnaryOperator mapper) in Java
- IntStream findFirst() in Java
- IntStream parallel() in Java
- IntStream empty() in Java with examples
- IntStream distinct() in Java with examples
- IntStream peek() in Java with examples
- IntStream average() in Java with Examples
- IntStream max() in Java with examples
- IntStream min() in Java with Examples
- IntStream count() in Java with examples
- IntStream skip() in Java
- IntStream filter() in Java with examples
- IntStream concat() in Java
- IntStream anyMatch() in Java with examples
- IntStream allMatch() in Java with examples
- IntStream generate() method in Java
- IntStream summaryStatistics() in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

