The Java conventional style to deal with collection is external iteration.
We deal with collection by
- Internal iteration
- External iteration
Where as internal iteration implies.
Java8 itself gives capability to iterate each and every element you just need to supply filter criteria.
- 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.
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.
Different kinds of streams
2. Parellal Stream-
Allows you to convert List into Stream Objects
You can do operate on your stream in parallel.
When you call parallelStream() it creates several threads and operates on our collection simultaneously.