diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 786d17c0d..b9403c793 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -7774,7 +7774,7 @@ public class StringUtils { } /** - * Check if a CharSequence starts with a specified prefix. + * Tests if a CharSequence starts with a specified prefix. * *

{@code null}s are handled without exceptions. Two {@code null} * references are considered to be equal. The comparison is case-sensitive.

@@ -7802,7 +7802,7 @@ public class StringUtils { } /** - * Check if a CharSequence starts with any of the provided case-sensitive prefixes. + * Tests if a CharSequence starts with any of the provided case-sensitive prefixes. * *
      * StringUtils.startsWithAny(null, null)      = false
@@ -7822,17 +7822,11 @@ public class StringUtils {
      *   the input {@code sequence} begins with any of the provided case-sensitive {@code searchStrings}.
      * @since 2.5
      * @since 3.0 Changed signature from startsWithAny(String, String[]) to startsWithAny(CharSequence, CharSequence...)
+     * @deprecated Use {@link Strings#startsWithAny(CharSequence, CharSequence...) Strings.CI.startsWithAny(CharSequence, CharSequence...)}
      */
+    @Deprecated
     public static boolean startsWithAny(final CharSequence sequence, final CharSequence... searchStrings) {
-        if (isEmpty(sequence) || ArrayUtils.isEmpty(searchStrings)) {
-            return false;
-        }
-        for (final CharSequence searchString : searchStrings) {
-            if (Strings.CS.startsWith(sequence, searchString)) {
-                return true;
-            }
-        }
-        return false;
+        return Strings.CS.startsWithAny(sequence, searchStrings);
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/lang3/Strings.java b/src/main/java/org/apache/commons/lang3/Strings.java
index d89fbae90..d9428e3d4 100644
--- a/src/main/java/org/apache/commons/lang3/Strings.java
+++ b/src/main/java/org/apache/commons/lang3/Strings.java
@@ -1410,4 +1410,41 @@ public abstract class Strings {
         }
         return CharSequenceUtils.regionMatches(str, ignoreCase, 0, prefix, 0, preLen);
     }
+
+    /**
+     * Tests if a CharSequence starts with any of the provided case-sensitive prefixes.
+     *
+     * 

+ * Case-sensitive examples + *

+ * + *
+     * StringUtils.startsWithAny(null, null)      = false
+     * StringUtils.startsWithAny(null, new String[] {"abc"})  = false
+     * StringUtils.startsWithAny("abcxyz", null)     = false
+     * StringUtils.startsWithAny("abcxyz", new String[] {""}) = true
+     * StringUtils.startsWithAny("abcxyz", new String[] {"abc"}) = true
+     * StringUtils.startsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true
+     * StringUtils.startsWithAny("abcxyz", null, "xyz", "ABCX") = false
+     * StringUtils.startsWithAny("ABCXYZ", null, "xyz", "abc") = false
+     * 
+ * + * @param sequence the CharSequence to check, may be null + * @param searchStrings the case-sensitive CharSequence prefixes, may be empty or contain {@code null} + * @see StringUtils#startsWith(CharSequence, CharSequence) + * @return {@code true} if the input {@code sequence} is {@code null} AND no {@code searchStrings} are provided, or the input {@code sequence} begins with + * any of the provided case-sensitive {@code searchStrings}. + */ + public boolean startsWithAny(final CharSequence sequence, final CharSequence... searchStrings) { + if (StringUtils.isEmpty(sequence) || ArrayUtils.isEmpty(searchStrings)) { + return false; + } + for (final CharSequence searchString : searchStrings) { + if (startsWith(sequence, searchString)) { + return true; + } + } + return false; + } + }