Mapping Operations in Stream
In this lesson, we will look at the mapping operations and the different ways to transform a stream.
We'll cover the following...
Mapping operations are those operations that transform the elements of a stream and return a new stream with transformed elements.
We can use a variety of methods to transform a stream into another stream object. The two most common methods used are map()
and flatMap()
.
Understanding map()
The map()
method takes a lambda expression as its only argument and uses it to change every individual element in the stream.
Its return value is a new stream object containing the changed elements.
Below is the method definition:
<R> Stream<R> map(Function<? super T, ? extends R> mapper) ...