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,
but the lambda expression passed in must be an instance of Function ( Figure 3-4 ). This is a
generic functional interface with only one argument.
Figure 3-4. The Function interface
 
Search WWH ::




Custom Search