A stream in Java is a sequence of elements that could be processed (mapped, filtered, transformed, reduced, and collected) either parallelly or sequentially in a pipeline of declarative operations using lambda expressions. It was introduced in Java 8 to change the way one can process enormous sets of data in a functional way, with lambda expressions instead of the traditional imperative way.
The Stream interface doesn't provide a lot of methods as other concurrency classes to monitor its status. Only the peek() method allows you to write log information about the elements that are being processed. In this recipe, you will learn how to use this method to write information about a stream.