Skip to content

Instantly share code, notes, and snippets.

@bandrzejczak
Created February 9, 2018 21:26
Show Gist options
  • Save bandrzejczak/b9412a7cd49c69f3991b77149f061efb to your computer and use it in GitHub Desktop.
Save bandrzejczak/b9412a7cd49c69f3991b77149f061efb to your computer and use it in GitHub Desktop.
public Map<String, List<String>> makeWordMap(
List<String> sentences) {
Map<String, List<String>> result =
new HashMap<String, List<String>>();
for (String sentence: sentences) {
for (String word: words(sentence)) {
List<String> sentencesForWord = result.get(word);
if (sentencesForWord == null) {
sentencesForWord = new ArrayList<String>();
result.put(word, sentencesForWord);
}
sentencesForWord.add(sentence);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment