import java.util.ArrayList; import java.util.List; import java.util.function.Function; public class FunctionExample { public static void main(String[] args) { List<Integer> numbers = new ArrayList<>(); numbers.add(1); numbers.add(2); numbers.add(3); Function<Integer, Integer> squareFunction = x -> x * x; List<Integer> squaredNumbers = numbers.stream() .map(squareFunction) .collect(Collectors.toList()); System.out.println(squaredNumbers); } }


上一篇:
下一篇:
切换中文