Java Reference
In-Depth Information
Figure 3-3. The map operation
Example 3-9. Converting strings to uppercase equivalents using map
List
<
String
>
collected
=
Stream
.
of
(
"a"
,
"b"
,
"hello"
)
.
map
(
string
->
string
.
toUpperCase
())
.
collect
(
toList
());
assertEquals
(
asList
(
"A"
,
"B"
,
"HELLO"
),
collected
);
The lambda expression passed into
map
both takes a
String
as its only argument and re-
turns a
String
. It isn't necessary for both the argument and the result to be the same type,
generic functional interface with only one argument.
Figure 3-4. The Function interface