Stream.of(T… values) in Java with examples
Stream of(T… values) returns a sequential ordered stream whose elements are the specified values. A sequential stream work just like for-loop using a single core. On the other hand, a Parallel stream divide the provided task into many and run them in different threads, utilizing multiple cores of the computer.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
static <T> Stream<T> of(T... values) Where, Stream is an interface and T is the type of stream elements. values represents the elements of the new stream and the function returns the new stream.
Example 1 : Stream of strings.
Geeks for Geeks
Example 2 : Stream of Integers.
5 7 9 12
Example 3 : Stream of Long primitives.
4 8 12 16 20