What is Streams?

Stream is a new abstract layer introduced in Java 8, It represents a sequence of objects from a source, which supports aggregate operations.

To understand better, lets take basic sql function distinct.

SELECT DISTINCT(USER_TYPE_ FROM [MYSCHEMA].[USER];

In the above SQL script, we perform Distinct operation using the DISTINCT method. which actually performs operation on the retrived data/rows.

Similarly Java8:Streams also performs operation or action on collective data.

Follow are the characteristic of Java8:Streams

  • Sequence of elements − Stream provides a set of elements of specific type in a sequential manner. A stream gets/computes/manipulated the elements/data. It never stores the manipulated elements/data.
  • Source − Stream accepts Collections, Arrays, or I/O resources as input source.
  • Aggregate operations − Stream supports aggregate operations such as filter, map, limit, reduce, find, match, & so on.
  • Pipelining − Most of the stream operations return stream itself so that their result can be pipelined. These operations are called intermediate operations and their function is to take input, process them, and return output to the target. collect() method is a terminal operation which is normally present at the end of the pipelining operation to mark the end of the stream.
  • Automatic iterations − Stream operations do the iterations internally over the source elements provided, in contrast to Collections where explicit iteration is required.

Lets continure in the next part..

Please disable your adblocker or whitelist this site! We Provide Free content and in return, all we ask is to allow serving Ads.

Pin It on Pinterest

Share This
%d bloggers like this: