Stream of() method in Java
Stream of(T t)
Stream of(T t) returns a sequential Stream containing a single element.
Syntax :
static Stream of(T t)
Parameters: This method accepts a mandatory parameter t which is the single element in the Stream.
Return Value: Stream of(T t) returns a sequential Stream containing the single specified element.
Example :
// Java code for Stream of(T t) // to get a sequential Stream // containing a single element. import java.util.*; import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // Creating an Stream having single element only Stream stream = Stream.of("Geeks"); // Displaying the Stream having single element stream.forEach(System.out::println); } } |
Geeks
Stream of(T… values)
Stream of(T… values) returns a sequential ordered stream whose elements are the specified values.
Syntax :
static Stream of(T... values)
Parameters: This method accepts a mandatory parameter values which are the elements of the new stream.
Return Value : Stream of(T… values) returns a sequential ordered stream whose elements are the specified values.
Example:
// Java code for Stream of(T... values) // to get a sequential ordered stream whose // elements are the specified values. import java.util.*; import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // Creating an Stream Stream stream = Stream.of("Geeks", "for", "Geeks"); // Displaying the sequential ordered stream stream.forEach(System.out::println); } } |
Geeks for Geeks
Recommended Posts:
- Difference between Stream.of() and Arrays.stream() method in Java
- Arrays stream() method in Java
- stream.limit() method in Java
- Stream.Builder add() method in Java
- Stream min() method in Java with Examples
- Stream.max() method in Java with Examples
- OptionalInt stream() method in Java with examples
- Stream generate() method in Java with examples
- Stream count() method in Java with examples
- OptionalDouble stream() method in Java with examples
- OptionalLong stream() method in Java with examples
- Stream skip() method in Java with examples
- Stream noneMatch() method in Java with examples
- Stream forEach() method in Java with examples
- Stream forEachOrdered() method in Java with examples
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.



