检查句子是否包含某些词

马可:

我有这样一个句子:

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!");
        }
    }
}
Mureinik:

我流的数组,然后检查是否字符串包含任何元素:

if (Arrays.stream(stringArray).anyMatch(s -> line.contains(s)) {
    // Do something...

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章