1.

What are Intermediate and Terminal operations?

Answer»

Intermediate Operations:

  • Process the stream elements.
  • Typically transforms a stream into another stream.
  • Are lazy, i.e., not executed TILL a terminal operation is invoked.
  • Does internal iteration of all source elements.
  • Any number of operations can be chained in the processing pipeline.
  • Operations are applied as per the DEFINED order.
  • Intermediate operations are mostly lambda functions.

Terminal Operations:

  • Kick-starts the Stream pipeline.
  • used to COLLECT the processed Stream data.
int count = Stream.of(1, 2, 3, 4, 5).filter(i -> i <4) // Intermediate Operation filter.count(); // Terminal Operation count


Discussion

No Comment Found