Answer by Pines Tran for Test if a string contains any of the strings from an...
In Apache common lang 3 support check contains any Strings. Try it:import org.apache.commons.lang3.StringUtils;...if(StringUtils.containsAny(string, item1, item2, item3)){ // your code}
View ArticleAnswer by H.Step for Test if a string contains any of the strings from an array
in Kotlinif ( arrayOf("one", "two", "three").find{ "onetw".contains(it) } != null ) { doStuff()}
View ArticleAnswer by Chandan Kolambe for Test if a string contains any of the strings...
We can also do like this:if (string.matches("^.*?((?i)item1|item2|item3).*$"))(?i): used for case insensitive.*? & .*$: used for checking whether it is present anywhere in between the string.
View ArticleAnswer by thanos.a for Test if a string contains any of the strings from an...
If you are seraching for wholewords you can do this that works caseinsensitive.private boolean containsKeyword(String line, String[] keywords){ String[] inputWords = line.split(""); for (String...
View ArticleAnswer by Arthur Vaïsse for Test if a string contains any of the strings from...
Since version 3.4 Apache Common Lang 3 implement the containsAny method.
View ArticleAnswer by vsingh for Test if a string contains any of the strings from an array
And if you are looking for case insensitive match, use patternPattern pattern = Pattern.compile("\\bitem1 |item2\\b",java.util.regex.Pattern.CASE_INSENSITIVE);Matcher matcher =...
View ArticleAnswer by Nicolas Filotto for Test if a string contains any of the strings...
If you use Java 8 or above, you can rely on the Stream API to do such thing:public static boolean containsItemFromArray(String inputString, String[] items) { // Convert the array of String items as a...
View ArticleAnswer by serup for Test if a string contains any of the strings from an array
Here is one solution :public static boolean containsAny(String str, String[] words){ boolean bResult=false; // will be set, if any of the words are found //String[] words = {"word1", "word2", "word3",...
View ArticleAnswer by renanleandrof for Test if a string contains any of the strings from...
import org.apache.commons.lang.StringUtils;String UtilsUse: StringUtils.indexOfAny(inputString, new String[]{item1, item2, item3})It will return the index of the string found or -1 if none is found.
View ArticleAnswer by Ivan Arrizabalaga for Test if a string contains any of the strings...
A more groovyesque approach would be to use inject in combination with metaClass:I would to love to say:String myInput="This string is FORBIDDEN"myInput.containsAny(["FORBIDDEN","NOT_ALLOWED"])...
View ArticleAnswer by gnomed for Test if a string contains any of the strings from an array
EDIT: Here is an update using the Java 8 Streaming API. So much cleaner. Can still be combined with regular expressions too.public static boolean stringContainsItemFromList(String inputStr, String[]...
View ArticleAnswer by Prahalad Deshpande for Test if a string contains any of the strings...
The below should work for you assuming Strings is the array that you are searching within:Arrays.binarySearch(Strings,"mykeytosearch",mysearchComparator);where mykeytosearch is the string that you want...
View ArticleAnswer by anubhava for Test if a string contains any of the strings from an...
You can use String#matches method like this:System.out.printf("Matches - [%s]%n", string.matches("^.*?(item1|item2|item3).*$"));
View ArticleAnswer by Garrett Hall for Test if a string contains any of the strings from...
if (Arrays.asList(array).contains(string))
View ArticleAnswer by Óscar López for Test if a string contains any of the strings from...
Try this:if (Arrays.stream(new String[] {item1, item2, item3}).anyMatch(inputStr::contains))
View ArticleAnswer by Roy Kachouh for Test if a string contains any of the strings from...
The easiest way would probably be to convert the array into a java.util.ArrayList. Once it is in an arraylist, you can easily leverage the contains method.public static boolean bagOfWords(String str){...
View ArticleTest if a string contains any of the strings from an array
How do I test a string to see if it contains any of the strings from an array?Instead of usingif (string.contains(item1) || string.contains(item2) || string.contains(item3))
View Article