If you read the specs, you see that StringUtils.containsIgnoreCase() checks if a String contains another String while StringUtils.equalsIgnoreCase() checks if two Strings are equal.

Answer from Keppil on Stack Overflow
🌐
Apache Commons
commons.apache.org › proper › commons-lang › apidocs › org › apache › commons › lang3 › StringUtils.html
StringUtils (Apache Commons Lang 3.20.0 API)
Tests if the CharSequence contains any character in the given set of characters. A null CharSequence will return false. A null or zero length search array will return false. StringUtils.containsAny(null, *) = false StringUtils.containsAny("", *) = false StringUtils.containsAny(*, null) = false ...
🌐
Apache Commons
commons.apache.org › proper › commons-lang › jacoco › org.apache.commons.lang3 › StringUtils.java.html
StringUtils.java
* * <p> * A {@code null} or empty ("") CharSequence will return {@code false}. * </p> * * <pre> * StringUtils.contains(null, *) = false * StringUtils.contains("", *) = false * StringUtils.contains("abc", 'a') = true * StringUtils.contains("abc", 'z') = false * </pre> * * @param seq the CharSequence ...
🌐
Educative
educative.io › answers › what-is-stringutilscontains-in-java
What is StringUtils.contains() in Java?
The function returns true if the character sequence contains a search sequence.
🌐
Tabnine
tabnine.com › home page › code › java › org.apache.commons.lang.stringutils
org.apache.commons.lang.StringUtils.contains java code examples | Tabnine
Boolean subbedEmailed = StringUtils.contains( body, "$" ); origin: apache/cloudstack · /** * Searches for a {@link MigrateDiskInfo} with the path matching the {@link DiskDef} path. */ protected MigrateDiskInfo searchDiskDefOnMigrateDiskInfoList(List<MigrateDiskInfo> migrateDiskInfoList, DiskDef disk) { for (MigrateDiskInfo migrateDiskInfo : migrateDiskInfoList) { if (StringUtils.contains(disk.getDiskPath(), migrateDiskInfo.getSerialNumber())) { return migrateDiskInfo; } } s_logger.debug(String.format("Cannot find Disk [uuid: %s] on the list of disks to be migrated", disk.getDiskPath())); return null; } origin: pig4cloud/pig ·
🌐
Spring
docs.spring.io › spring-framework › docs › current › javadoc-api › org › springframework › util › StringUtils.html
StringUtils (Spring Framework 7.0.5 API)
More specifically, this method returns true if the CharSequence is not null, its length is greater than 0, and it contains at least one non-whitespace character. StringUtils.hasText(null) = false StringUtils.hasText("") = false StringUtils.hasText(" ") = false StringUtils.hasText("12345") = true StringUtils.hasText(" 12345 ") = true
🌐
Qvera
qvera.com › kb › index.php › 2000 › how-to-use-stringutils-containsany
How to use StringUtils.ContainsAny? - Knowledge Base - Qvera
I see a documented function for StringUtils.ContainsAny but not much information beyond the signature. ... Does it match by RegEx or something else?
🌐
Medium
medium.com › @vino7tech › useful-stringutils-methods-in-java-833dc5236f0a
Useful StringUtils Methods in Java | by Vinotech | Medium
September 29, 2024 - Here is a list of commonly used ... use cases: boolean hasLength(@Nullable String str): Checks whether the given String has length (i.e., not null and not empty). boolean hasText(@Nullable String str): Checks whether the ...
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-3.3 › org › apache › commons › lang3 › StringUtils.html
StringUtils (Apache Commons Lang 3.3 API)
Checks if CharSequence contains a search character, handling null. This method uses String.indexOf(int) if possible. A null or empty ("") CharSequence will return false. StringUtils.contains(null, *) = false StringUtils.contains("", *) = false StringUtils.contains("abc", 'a') = true ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › string-handling-with-apache-commons-stringutils-class-in-java
String Handling with Apache Commons' StringUtils Class in Java - GeeksforGeeks
April 28, 2025 - isNumeric(String str): This method checks if a String contains only numeric characters (0-9) and optionally a minus sign at the beginning. It returns true if the String is numeric, and false otherwise. Below Are the Programs that demonstrate StringUtility class Methods. ... import org.apache.commons.lang3.StringUtils; public class StringUtilsExample { public static void main(String[] args) { String str = " hello world "; // isEmpty() example boolean empty = StringUtils.isEmpty(str); System.out.println("Is the string empty?
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-2.6 › org › apache › commons › lang › StringUtils.html
StringUtils (Commons Lang 2.6 API)
Checks if String contains a search String, handling null. This method uses String.indexOf(String). A null String will return false. StringUtils.contains(null, *) = false StringUtils.contains(*, null) = false StringUtils.contains("", "") = true StringUtils.contains("abc", "") = true ...
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-release › org › apache › commons › lang3 › StringUtils.html
StringUtils (Apache Commons Lang 3.11 API)
Checks if the CharSequence contains any character in the given set of characters. A null CharSequence will return false. A null or zero length search array will return false. StringUtils.containsAny(null, *) = false StringUtils.containsAny("", *) = false StringUtils.containsAny(*, null) = false ...
🌐
Stack Abuse
stackabuse.com › guide-to-apache-commons-stringutils-class-in-java
Guide to Apache Commons' StringUtils Class in Java
September 27, 2023 - With the commons-lang3 dependency in our project, we can move on to discussing some of the most used methods from StringUtils. Let's get started! Comparing Strings, checking if they're empty, or blank, or simply checking if they're equal are pretty common operations. Let's start off with some comparison-related methods. These two methods are pretty self explanatory - they're both used to check if a String contains any text.
🌐
Baeldung
baeldung.com › home › java › java string › string processing with apache commons lang 3
String Processing with Apache Commons Lang 3 | Baeldung
January 8, 2024 - String string = "baeldung.com"; boolean contained1 = StringUtils.containsAny(string, 'a', 'b', 'c'); boolean contained2 = StringUtils.containsAny(string, 'x', 'y', 'z'); boolean contained3 = StringUtils.containsAny(string, "abc"); boolean contained4 ...
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-3.1 › org › apache › commons › lang3 › StringUtils.html
StringUtils (Commons Lang 3.1 API)
Checks if CharSequence contains a search character, handling null. This method uses String.indexOf(int) if possible. A null or empty ("") CharSequence will return false. StringUtils.contains(null, *) = false StringUtils.contains("", *) = false StringUtils.contains("abc", 'a') = true ...
🌐
Educative
educative.io › answers › what-is-stringutilscontainsany-in-java
What is StringUtils.containsAny() in Java?
Since the string contains at least one character from the search string (abc), the function returns true.
🌐
Codehaus-plexus
codehaus-plexus.github.io › plexus-utils › apidocs › org › codehaus › plexus › util › StringUtils.html
StringUtils (Plexus Common Utilities 4.0.2 API)
Checks if String contains a search String, handling null. This method uses String.indexOf(int). A null String will return false. StringUtils.contains(null, *) = false StringUtils.contains(*, null) = false StringUtils.contains("", "") = true StringUtils.contains("abc", "") = true StringUtil...
🌐
Stack Abuse
stackabuse.com › java-check-if-string-contains-a-substring
Java: Check if String Contains a Substring
February 27, 2020 - This can be a bit misleading, so another way to put it is - it checks if the character sequence is made up of only the specified characters. It accepts either a String or a character sequence: String string = "Hello World!" System.out.println(StringUtils.containsOnly(string, 'HleWord!')); ...
Top answer
1 of 16
270

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[] items) {
    return Arrays.stream(items).anyMatch(inputStr::contains);
}

Also, if we change the input type to a List instead of an array we can use items.stream().anyMatch(inputStr::contains).

You can also use .filter(inputStr::contains).findAny() if you wish to return the matching string.

Important: the above code can be done using parallelStream() but most of the time this will actually hinder performance. See this question for more details on parallel streaming.


Original slightly dated answer:

Here is a (VERY BASIC) static method. Note that it is case sensitive on the comparison strings. A primitive way to make it case insensitive would be to call toLowerCase() or toUpperCase() on both the input and test strings.

If you need to do anything more complicated than this, I would recommend looking at the Pattern and Matcher classes and learning how to do some regular expressions. Once you understand those, you can use those classes or the String.matches() helper method.

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;
}
2 of 16
61
import org.apache.commons.lang.StringUtils;

String Utils

Use:

StringUtils.indexOfAny(inputString, new String[]{item1, item2, item3})

It will return the index of the string found or -1 if none is found.