Stream.of(T t) in Java with examples
Stream of(T t) returns a sequential Stream containing a single element i.e, a singleton sequential stream. 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.
static <T> Stream<T> of(T t) Where, Stream is an interface and T is the type of stream elements. t is the single element and the function returns a singleton sequential stream.
Example 1 : Singleton string stream.
Example 2 : Singleton Integer Stream.
Example 3 : Singleton Long stream.
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.