回答編集履歴

3

bug fix

2019/08/07 08:38

投稿

BluOxy
BluOxy

スコア2663

test CHANGED
@@ -64,7 +64,7 @@
64
64
 
65
65
  String[] elements = line.split("\t", 0);
66
66
 
67
- if (tsvMap.containsKey(elements[0])) {
67
+ if (!tsvMap.containsKey(elements[0])) {
68
68
 
69
69
  List<String> values = new ArrayList<>();
70
70
 

2

typo

2019/08/07 08:38

投稿

BluOxy
BluOxy

スコア2663

test CHANGED
@@ -64,15 +64,15 @@
64
64
 
65
65
  String[] elements = line.split("\t", 0);
66
66
 
67
- if (tsv.containsKey(elements[0])) {
67
+ if (tsvMap.containsKey(elements[0])) {
68
68
 
69
69
  List<String> values = new ArrayList<>();
70
70
 
71
- tsv.put(elements[0], values);
71
+ tsvMap.put(elements[0], values);
72
72
 
73
73
  }
74
74
 
75
- tsv.get(elements[0]).add(elements[1]);
75
+ tsvMap.get(elements[0]).add(elements[1]);
76
76
 
77
77
  }
78
78
 

1

変数名の変更と、HashMapの拡張forが構文エラーな点を修正

2019/08/07 08:32

投稿

BluOxy
BluOxy

スコア2663

test CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  public static void main(String args[]) {
34
34
 
35
- List<String> lines = new ArrayList<>();
35
+ List<String> lines = new ArrayList<>();
36
36
 
37
37
  try {
38
38
 
@@ -62,17 +62,17 @@
62
62
 
63
63
  for(String line : lines){
64
64
 
65
- String[] split_line = line.split("\t", 0);
65
+ String[] elements = line.split("\t", 0);
66
66
 
67
- if (tsv.containsKey(split_line[0])) {
67
+ if (tsv.containsKey(elements[0])) {
68
68
 
69
69
  List<String> values = new ArrayList<>();
70
70
 
71
- tsv.put(split_line[0], values);
71
+ tsv.put(elements[0], values);
72
72
 
73
73
  }
74
74
 
75
- tsv.get(split_line[0]).add(split_line[1]);
75
+ tsv.get(elements[0]).add(elements[1]);
76
76
 
77
77
  }
78
78
 
@@ -84,7 +84,7 @@
84
84
 
85
85
  public static void display(HashMap<String,List<String>> tsvMap){
86
86
 
87
- for (Set<Entry<String, List<String>>> entry : tsvMap.entrySet()) {
87
+ for (Entry<String, List<String>> entry : tsvMap.entrySet()) {
88
88
 
89
89
  System.out.println(entry.getKey() + "\t" + String.join(":",key.getValue()));
90
90