... and streams with an array of Strings.

17.11.1 Mapping Strings to Uppercase

The stream pipeline in lines 17–19

Arrays.stream(strings) 
      .map(String::toUpperCase) 
      .collect(Collectors.toList()));

displays the Strings in uppercase letters. To do so, line 17 creates a Stream<String> from the array strings, then line 18 maps each String to its uppercase version by calling String instance method toUpperCase on each stream element.

Stream method map receives an object that implements the Function functional interface, representing a one-parameter method that performs a task with its parameter then returns the result. In this case, we pass to map an unbound instance method reference of the form ClassName::instanceMethodName (String::toUpperCase). “Unbound” ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.