我有一句话,类似于:
I`ve got a Pc
并且有一组词:
Hello
world
Pc
dog
我该如何检查一句话是否包含这些单词?在这个例子中,我会匹配到Pc
。
这是我目前拥有的:
public class SentenceWordExample {
public static void main(String[] args) {
String sentence = "I`ve got a Pc";
String[] words = { "Hello", "world", "Pc", "dog" };
// I know this does not work, but how to continue from here?
if (line.contains(words) {
System.out.println("Match!");
} else {
System.out.println("No match!");
}
}
}
line.contains(arrayElement)
。如果有任何匹配项,那么就是有匹配项了。 - Zabuzard