回答編集履歴
2
Functionのimport static忘れ
test
CHANGED
@@ -42,6 +42,8 @@
|
|
42
42
|
|
43
43
|
import static java.util.stream.Collectors.*;
|
44
44
|
|
45
|
+
import static java.util.function.Function.*;
|
46
|
+
|
45
47
|
|
46
48
|
|
47
49
|
public class Main {
|
1
import staticですっきり書いてみた
test
CHANGED
@@ -27,3 +27,37 @@
|
|
27
27
|
}
|
28
28
|
|
29
29
|
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
さらにStreamを使うとyuba様の回答のようになりますが、
|
34
|
+
|
35
|
+
それをimport staticを使って少しだけきれいに書いてみた
|
36
|
+
|
37
|
+
```java
|
38
|
+
|
39
|
+
import java.util.Map;
|
40
|
+
|
41
|
+
import java.util.Arrays;
|
42
|
+
|
43
|
+
import static java.util.stream.Collectors.*;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
public class Main {
|
48
|
+
|
49
|
+
public static void main(String[] args)
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
Map<String, Long> map = Arrays.asList("a", "a", "b")
|
54
|
+
|
55
|
+
.stream()
|
56
|
+
|
57
|
+
.collect(groupingBy(identity(), counting()));
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
```
|