回答編集履歴

2

ファイルパスを変更

2018/11/08 04:27

投稿

root_jp
root_jp

スコア4666

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(filePath))) {
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メソッドを追加

2018/11/08 04:27

投稿

root_jp
root_jp

スコア4666

test CHANGED
@@ -1,16 +1,22 @@
1
1
  ```Java
2
2
 
3
- try (Stream<String> lines = Files.lines(Paths.get("kaikei.txt"))) {
3
+ public static void main(final String[] args) throws Exception {
4
4
 
5
- Map<String, Integer> summary = lines.map(line -> {
5
+ final String filePath = "C:\eclipse_workspace\my-project\src\sample\data.txt";
6
6
 
7
- String[] split = line.split(",");
7
+ try (Stream<String> lines = Files.lines(Paths.get(filePath))) {
8
8
 
9
- return new String[] { split[0], split[1].split(":")[1] };
9
+ Map<String, Integer> summary = lines.map(line -> {
10
10
 
11
- }).collect(Collectors.groupingBy(array -> array[0], TreeMap::new, Collectors.summingInt(array -> Integer.parseInt(array[1]))));
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