MCPcopy Create free account
hub / github.com/apache/commons-lang / startsWith

Method startsWith

src/main/java/org/apache/commons/lang3/Strings.java:1422–1431  ·  view source on GitHub ↗

Tests if a CharSequence starts with a specified prefix. nulls are handled without exceptions. Two null references are considered to be equal. Case-sensitive examples Strings.CS.startsWith(null, null) = true Strings.CS.startsWith(null, "abc") = fals

(final CharSequence str, final CharSequence prefix)

Source from the content-addressed store, hash-verified

1420 * @return {@code true} if the CharSequence starts with the prefix or both {@code null}
1421 */
1422 public boolean startsWith(final CharSequence str, final CharSequence prefix) {
1423 if (str == null || prefix == null) {
1424 return str == prefix;
1425 }
1426 final int preLen = prefix.length();
1427 if (preLen > str.length()) {
1428 return false;
1429 }
1430 return CharSequenceUtils.regionMatches(str, ignoreCase, 0, prefix, 0, preLen);
1431 }
1432
1433 /**
1434 * Tests if a CharSequence starts with any of the provided prefixes.

Calls 2

regionMatchesMethod · 0.95
lengthMethod · 0.45