Reputation: 601
I have a List stopWord(each string is only one word) and I have a string phrases(at least 2 words). I want to check if my phrases includes one of the stopWord's element in Java. How can I do that?
if(!stopWord.contains(phrase.toLowerCase())
String delims = "[ ,-.…•“”‘’:;!()/?\"]+";
I used this code but I think it doesn't understand String with 2 words which is my phrase. stopWord's each element is single word. I didn't split my phrase. Cuz I'm dealing with large amount of data. Is there a simplier way?
Upvotes: 1
Views: 70
Reputation: 1944
String[] words = phrase.split(" ");
for (String word : words)
{
if (stopWord.contains(word))
{
// do here whatever you need :)
}
}
Upvotes: 1
Reputation: 1944
If you're using Java 8:
String phrase = "your phrase";
if (stopWord.parallelStream().anyMatch(s -> phrase.contains(s)))
{
// do stuff here
}
Upvotes: 1