java - One line check if String contains bannedSubstrings -
i have string title , list<string> bannedsubstrings. want perform 1 line check if title free of bannedsubstrings.
my approach:
if(bannedsubstrings.stream().filter(bannedsubstring -> title.contains(bannedsubstring)).isempty()){ ... } unfortunately, there no isempty() method streams. how solve problem? there 1 line solution?
sounds want read on anymatch:
if (bannedsubstrings.stream().anymatch(title::contains)) { // bad words! } inversely, there's nonematch:
if (bannedsubstrings.stream().nonematch(title::contains)) { // no bad words :d } this isn't efficient if title long string (but titles aren't supposed long, suppose).
Comments
Post a Comment