Streams

Streams:

  • Process collection of objects
  • It is not DS it take input from collection, array and I/O channels
  • Did Not change data structure only provide result according to pipelined methods.
  • Intermediate Operation
    • Map
      • The map method is used to map the items in the collection to other objects according to the Predicate passed as argument.
    • Filter
      • The filter method is used to select elements as per the Predicate passed as argument.
    • Sort
      • The sorted method is used to sort the stream.
  • Terminal Operation
    • Collect
      • The collect method is used to return the result of the intermediate operations performed on the stream.
    • For each
      • The forEach method is used to iterate through every element of the stream.
    • Reduce
      • The reduce method is used to reduce the elements of a stream to a single value.
      • The reduce method takes a BinaryOperator as a parameter.
      • number.stream().filter(x->x%2==0).reduce(0,(ans,i)-> ans+i);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: