:
Iterate over the words ( stream) and returns true if any words (with a name w) match the condition ( contains)
public static boolean isForbidden(String word, List<String> words) {
return words.stream().anyMatch(w -> (word.toLowerCase().contains(w.toLowerCase())));
}
Using regex , he will build the template itself fromList
public static boolean isForbidden1(String word, List<String> words) {
String forbiddenWordPattern = String.join("|", words);
return Pattern.compile(forbiddenWordPattern, Pattern.CASE_INSENSITIVE)
.matcher(word)
.find();
}
source
share