Skip to content

StringUtils.containsAny

Signature: StringUtils.containsAny(inputString, searchChars)

Returns: Boolean result - true if the inputString contains any character in the searchChars, false if not or null inputString

Checks if inputString contains any character in the searchChars, handling null. A null inputString will return false.

Parameters

Type Name Description Default
String inputString the String to check, may be null
String or char[] searchChars the characters to find

Example

// Example usages of StringUtils.containsAny
var text = "Do I contain what you are looking for?";


// Example: searchChars as String
if (StringUtils.containsAny(text, "zvu")) {
   // At least one of 'z', 'v' or 'u' is present -- 'u' matches. The search is
   // case-sensitive, so searching "zv" alone would not match.
}


// Example: searchChars as char[]
if (StringUtils.containsAny(
       text,
       ['z', 'v', 'u']
    )) {
   // Same check with the search characters supplied as an array.
}