回答編集履歴
3
bug fix
answer
CHANGED
@@ -31,7 +31,7 @@
|
|
31
31
|
HashMap<String, List<String>> tsvMap = new HashMap<>();
|
32
32
|
for(String line : lines){
|
33
33
|
String[] elements = line.split("\t", 0);
|
34
|
-
if (tsvMap.containsKey(elements[0])) {
|
34
|
+
if (!tsvMap.containsKey(elements[0])) {
|
35
35
|
List<String> values = new ArrayList<>();
|
36
36
|
tsvMap.put(elements[0], values);
|
37
37
|
}
|
2
typo
answer
CHANGED
@@ -31,11 +31,11 @@
|
|
31
31
|
HashMap<String, List<String>> tsvMap = new HashMap<>();
|
32
32
|
for(String line : lines){
|
33
33
|
String[] elements = line.split("\t", 0);
|
34
|
-
if (
|
34
|
+
if (tsvMap.containsKey(elements[0])) {
|
35
35
|
List<String> values = new ArrayList<>();
|
36
|
-
|
36
|
+
tsvMap.put(elements[0], values);
|
37
37
|
}
|
38
|
-
|
38
|
+
tsvMap.get(elements[0]).add(elements[1]);
|
39
39
|
}
|
40
40
|
return tsvMap;
|
41
41
|
}
|
1
変数名の変更と、HashMapの拡張forが構文エラーな点を修正
answer
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
public class Test {
|
17
17
|
public static void main(String args[]) {
|
18
|
-
|
18
|
+
List<String> lines = new ArrayList<>();
|
19
19
|
try {
|
20
20
|
Path path = Paths.get("test.tsv");
|
21
21
|
lines = Files.readAllLines(path);
|
@@ -30,18 +30,18 @@
|
|
30
30
|
public static HashMap<String, List<String>> createTsvAsMap(List<String> lines){
|
31
31
|
HashMap<String, List<String>> tsvMap = new HashMap<>();
|
32
32
|
for(String line : lines){
|
33
|
-
String[]
|
33
|
+
String[] elements = line.split("\t", 0);
|
34
|
-
if (tsv.containsKey(
|
34
|
+
if (tsv.containsKey(elements[0])) {
|
35
35
|
List<String> values = new ArrayList<>();
|
36
|
-
tsv.put(
|
36
|
+
tsv.put(elements[0], values);
|
37
37
|
}
|
38
|
-
tsv.get(
|
38
|
+
tsv.get(elements[0]).add(elements[1]);
|
39
39
|
}
|
40
40
|
return tsvMap;
|
41
41
|
}
|
42
42
|
|
43
43
|
public static void display(HashMap<String,List<String>> tsvMap){
|
44
|
-
for (
|
44
|
+
for (Entry<String, List<String>> entry : tsvMap.entrySet()) {
|
45
45
|
System.out.println(entry.getKey() + "\t" + String.join(":",key.getValue()));
|
46
46
|
}
|
47
47
|
}
|