Slide 9
Slide 9 text
Javaの map メソッドの利用例
// IntStream => int[]
jshell> IntStream.rangeClosed(1, 10).
...> map(n -> (int) Math.pow(2, n)). // int => int
...> toArray()
$1 ==> int[10] { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 }
// Set => Stream => Stream
// => Map
jshell> Set.of("abricot", "banane", "citron").
...> stream().
...> map(String::length). // String => Integer
...> collect(Collectors.groupingBy(
...> Function.identity(), // ここでキー変換したほうが効率的
...> Collectors.counting()
...> ))
$2 ==> {6=2, 7=1}
9