回答編集履歴
2
ファイルパスを変更
test
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
public static void main(final String[] args) throws Exception {
|
4
4
|
|
5
|
-
final String filePath = "C:\eclipse_workspace\my-project\src\sample\data.txt";
|
6
|
-
|
7
|
-
try (Stream<String> lines = Files.lines(Paths.get(
|
5
|
+
try (Stream<String> lines = Files.lines(Paths.get("kaikei.txt"))) {
|
8
6
|
|
9
7
|
Map<String, Integer> summary = lines.map(line -> {
|
10
8
|
|
1
mainメソッドを追加
test
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
```Java
|
2
2
|
|
3
|
-
t
|
3
|
+
public static void main(final String[] args) throws Exception {
|
4
4
|
|
5
|
-
|
5
|
+
final String filePath = "C:\eclipse_workspace\my-project\src\sample\data.txt";
|
6
6
|
|
7
|
-
|
7
|
+
try (Stream<String> lines = Files.lines(Paths.get(filePath))) {
|
8
8
|
|
9
|
-
|
9
|
+
Map<String, Integer> summary = lines.map(line -> {
|
10
10
|
|
11
|
-
|
11
|
+
String[] split = line.split(",");
|
12
12
|
|
13
|
+
return new String[] { split[0], split[1].split(":")[1] };
|
14
|
+
|
15
|
+
}).collect(Collectors.groupingBy(array -> array[0], TreeMap::new, Collectors.summingInt(array -> Integer.parseInt(array[1]))));
|
16
|
+
|
13
|
-
summary.entrySet().stream().forEach(entry -> System.out.println(entry.getKey() + ": " + entry.getValue()));
|
17
|
+
summary.entrySet().stream().forEach(entry -> System.out.println(entry.getKey() + ": " + entry.getValue()));
|
18
|
+
|
19
|
+
}
|
14
20
|
|
15
21
|
}
|
16
22
|
|