Recap Streams
Abgabe 3
Häufig gesehene Lösung mit for each
@Override
public Map<Long, Integer> idsAndCountFromInput(String inputLine, Map<String, Long> keywordsToIds) {
Map<Long, Integer> res = new HashMap<>();
inputLine = inputLine.replaceAll("[,\\.]", "");
String[] words = inputLine.split("\\s");
for (String word : words) {
if (keywordsToIds.containsKey(word)) {
res.put(keywordsToIds.get(word), res.getOrDefault(word, 0) + 1);
}
}
return res;
}