In this guide we are going to see different examples of Java Stream map method, Java Streams introduced in Java 8.

Java Stream map method signature

Copy to Clipboard

Stream.map() method is a Stream intermediate operation, an intermediate operation transform a stream into another stream. Java Stream map method produces a new stream after applying a function to each element of the original stream. The new stream could be of different type.

Java Stream map method Example1

Below example demonstrates how to increase each Employee salary by 10000.

Copy to Clipboard

Output:

Copy to Clipboard

Java Stream map method Example2

Below example demonstrates how to change each Employee name to upper case.

Copy to Clipboard

Output:

Copy to Clipboard

Java Stream map() with filter() Example

If we want to filter the elements of stream based on condition we can use Stram.filter(). Below example demonstrates how to list out the employees whose salary greater than 80000.

Copy to Clipboard

Output:

Copy to Clipboard