マルコ:
私のような文があります。
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...