Convert string to uppercase with method reference

Description

The following code shows how to convert string to uppercase with method reference.

Example


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
/*w ww.  j a  v  a  2 s.  c  o  m*/
public class Main {

   public static void main(String[] args) {
     List<String> names = Arrays.asList("john", "jane", "oliver");
     System.out.println(transformStrings(names, String::toUpperCase));

   }
   
   private static List<String> transformStrings(List<String> names, Function<String, String> fx) {
     List<String> appliedNames = new ArrayList<>();
     for (String n : names) {
        appliedNames.add(fx.apply(n));
     }
     return appliedNames;
  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Examples »




Average
Filter
Group
IntStream
Map
Partition
Reduce
Sort
Sum