Java 8 Stream of example

Previous
Next

In this post, we will see about Java 8 Stream’s of method example.
Stream’s of method is static method and used to create stream of given type.
For example:

There are two overloaded version of Stream’s of method.
1) static <T> Stream<T> of(T… values)
Returns a sequential ordered stream whose elements are the specified values.
2) static <T> Stream<T> of(T t)
Returns a sequential Stream containing a single element.

Java Stream of example

Create a class named Java8StreamOfExample as below:

When you run above program, you will get below output:

India
China
Bhutan
Nepal

Another example

When you run above program, you will get below output:

4.0
6.8
8.6

Previous
Next

Join Our News Letter – Stay Updated

Subscribe to Awesome Java Content.




Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog