I want to know how to convert lambda expression printing string length to using '::' operation.
String[] arr = new String[]{"1", "234", "56"};
Arrays.stream(arr).forEach(s -> System.out.println(s.length()));
Excellent question! Here you could do so twice. Once to map each String
to an int
by calling length()
on each String
and a second time by calling println(int)
on System.out
. Like,
Arrays.stream(arr).mapToInt(String::length).forEach(System.out::println);