Java8 Part2 Streams

Java8 Streams
The Java conventional style to deal with collection is external iteration.
We deal with collection by

  • Internal iteration
  • External iteration
The term external iteration implies you need to explicitly take care of iteration of elements in collection then validate each element and add it to the other list.

Where as internal iteration implies.
Java8 itself gives capability to iterate each and every element you just need to supply filter criteria.

For internal iteration it comes with three important methods to deal with collection of objects.


  • Map method allows you to process one by one element of collection.
  • Takes argument as lambda expression
  • apply lambda expression on every element
  • Return results.
Map generates each processed element in the seperate streams
FlatMap: whereas flatmap each processed element flattened into the seperate stream.

Produces a new Stream that contains only the elements of the original Stream that pass a given test.


  • Reductions operation occurs at the end of the all operations.
  • Hence it is also termed as terminal operation.
Generally the methods used for reductions are
1. Sum
3. Count
4. toArray

Different kinds of streams
2. Parellal Stream-

Allows you to convert List into Stream Objects
Method :listObj.strean()

2.Parallel Stream
You can do operate on your stream in parallel.
When you call parallelStream() it creates several threads and operates on our collection simultaneously.

Leave a Reply

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