top of page

Basic usage of Stream API

Basic usage of Stream API


First of all, a Stream is a sequence of elements and it supports the different kind of operations to the action of logical or mathematical calculation upon those elements.

Streams can be created from various data sources, especially collections. For example, “Lists” and “Sets”.


There are two kinds of streams which are sequential stream and parallel stream.

We can use "stream()" method for sequential stream and "parallelStream()" method for parallel stream which is capable of operating on multiple threads.


Let’s see about the example of the sequential stream and parallel stream:


Sequential stream


Parallel stream

Only different are the "stream()" and "parallelStream()" but streams can be executed in parallel to increase the runtime performance on large amount of input elements.


The output results will be same for above two example as following:





Kommentare


Single post: Blog_Single_Post_Widget
bottom of page