Streams

1.Overview

Streams are introduced in Java in Stream API to handle the operations on the list of elements in functional programming approach.

Using Streams we can do multiple operations on the list of elements.

We can do filtering(Filter) or ordering (Map) etc., on the list of elements/collections in the stream.

Second is we can do counting/Sum/Average (Reduce)etc., on the filtered/ordered list of elements/collections.

Hence Streams works on the [Map Reduce] transformations over the collections. Below is the simple syntax of the streams.

1.1 Streams Filter

1.1.1. stream.filter() Native Java Implementation

Below example shows how streams use Predicate Object as an argument for filter() method to filter the collections.

Result

1.1.2. stream.filter() Lambda Java Implementation

Below is the example of how Streams using Predicate as an argument for filter() method to filter the collections using lambda operations

Result

1.2 Streams Map

1.1.1.stream.map() Native Implementation

Below example shows how streams use Function Object as an argument for map() method to do operation over the collections, and return the collections.

Result

1.1.2. stream.map()- Lambda Implementation

Below example shows how streams use Function Object as an argument for map() method to do operation over the collections, and return the collections.

Result

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *