Removed unnecessary toString() 💀

This commit is contained in:
TiagoRG 2023-05-10 21:22:12 +01:00
parent a9944f06f7
commit 71c1e01cc6
1 changed files with 2 additions and 15 deletions

View File

@ -8,20 +8,7 @@ import java.util.*;
public class WordPairCounter { public class WordPairCounter {
public static void main(String[] args) { public static void main(String[] args) {
TreeMap<String, HashMap<String, Integer>> wordPairs = new TreeMap<>() { TreeMap<String, HashMap<String, Integer>> wordPairs = new TreeMap<>();
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (String word1 : this.keySet()) {
sb.append(word1).append("={");
for (String word2 : this.get(word1).keySet()) {
sb.append(word2).append("=").append(this.get(word1).get(word2)).append(", ");
}
sb.delete(sb.length()-2, sb.length()).append("}\n");
}
return sb.toString();
}
};
String text = ""; String text = "";
Path path = Paths.get((new Scanner(System.in)).nextLine()); Path path = Paths.get((new Scanner(System.in)).nextLine());
@ -42,6 +29,6 @@ public class WordPairCounter {
word1Pair.put(word2, word1Pair.getOrDefault(word2, 0) + 1); word1Pair.put(word2, word1Pair.getOrDefault(word2, 0) + 1);
} }
System.out.println(wordPairs); wordPairs.entrySet().forEach(System.out::println);
} }
} }