【发布时间】:2020-04-29 16:53:01
【问题描述】:
例如,如何检查 listcontainsThese 中的单词是否存在于 listsentences 中以及有多少?
List<String> sentences = Arrays.asList("wish you a good day", "warm day", "sounds good");
List<String> containsThese = Arrays.asList("cool", "day", "good");
我在做什么:
for (int i = 0; i < sentences.size(); i++){
String words = sentences.get(i);
// so here I have each sentence separately
// but how to iterate through it and add each word to another ArrayList or something?
// so later can compare to it to 'containsThese' ?
}
欢迎提出建议,谢谢。
【问题讨论】:
-
嗯,有两个想法。
String#contains和某种Map将是一些开始的地方
标签: java arrays arraylist hashmap string-comparison