EDIT: This is an update using the Java 8 Streaming API. So much cleaner. Can also be combined with regular expressions.
public static boolean stringContainsItemFromList(String inputStr, String[] items) { return Arrays.stream(items).parallel().anyMatch(inputStr::contains); }
In addition, if we change the input type to a list instead of an array, we can use items.parallelStream().anyMatch(inputStr::contains) .
You can also use .filter(inputStr::contains).findAny() if you want to return the corresponding string.
Original slightly dated answer:
Here is a static method (VERY BASIC). Note that it is case sensitive in comparison strings. A primitive way to make it case insensitive would be to toLowerCase() or toUpperCase() on the input and test lines.
If you need to do something more complex, I would recommend looking at Pattern and Matcher and learning how to perform some regular expressions. String.matches() you understand them, you can use these classes or the helper method String.matches() .
public static boolean stringContainsItemFromList(String inputStr, String[] items) { for(int i =0; i < items.length; i++) { if(inputStr.contains(items[i])) { return true; } } return false; }
gnomed Jan 24 2018-12-12T00: 00Z
source share