We can also get an instance of Stream by providing its elements to the of function. The of function works in a similar way to the Observable.just method from RxJava/RxKotlin.
Have a look at the following example:
fun main(args: Array<String>) { val stream = Stream.of("Item 1",2,"Item 3",4,5.0,"Item 6") println("Items in Stream = ${stream.collect(Collectors.toList())}") }
The output is as follows:
Straightforward and easy, isn't it?