Stream in java is the major concept of Java 8. In java stream operations, we have two parts of operation one is intermediate operations and terminal operations. In this post we will discuss the java stream collect, java stream foreach, stream sorted, java stream filter, java stream distinct, java stream reduce, java stream collect, stream reduce.
Java stream operations
Java Stream is divided into intermediate operations and terminal operations.
1. Intermediate operations
By use of Stream, you can perform various operations. Some operations that return a new stream is called intermediate operation. This operation is lazy in nature.
1. By use of intermediate operation, you can perform the various operations in a row.
Because intermediate operation produces a stream and sends next to operation.
2. The intermediate operations could not able to produce the final result.
3. Intermediate operation is used by the terminal operation as an input.
We will discuss some intermediate operations:
4. Stream .distinct()
2. Terminal operations
The terminal operation doesn’t return any stream. It returns a result of a certain type.
1. The terminal operations take Stream as input and produce the result.
2. After completion of the Terminal operation, you can’t use the Stream.
3. Terminal operation is eager in nature. The terminal operation processes all the elements of the stream before returning the result.
We will discuss some Terminal operations:
1 thought on “Java stream operations in java”
I’m still learning from you, but I’m making my way to the top as well. I absolutely liked reading everything that is posted on your website.Keep the aarticles coming. I enjoyed it!