Java Utililty Methods String Starts Wtih

List of utility methods to do String Starts Wtih

Description

The list of methods to do String Starts Wtih are organized into topic(s).

Method

booleanstartsWithIgnoreCase(final String str, final String prefix)
starts With Ignore Case
if (str == null || prefix == null) {
    return false;
if (str.startsWith(prefix)) {
    return true;
if (str.length() < prefix.length()) {
    return false;
...
booleanstartsWithIgnoreCase(final String string, final String start)
starts With Ignore Case
return startsWithIgnoreCase(string, start, 0);
booleanstartsWithIgnoreCase(final String stringToCheck, final String prefix)
Code copied from HtmlUnit (src/main/java/com/gargoylesoftware/htmlunit/TextUtil.java) (https://htmlunit.svn.sourceforge.net/svnroot/htmlunit/trunk/htmlunit - commit 5556)
if (prefix.length() == 0) {
    throw new IllegalArgumentException("Prefix may not be empty");
final int prefixLength = prefix.length();
if (stringToCheck.length() < prefixLength) {
    return false;
return stringToCheck.substring(0, prefixLength).toLowerCase().equals(prefix.toLowerCase());
...
booleanstartsWithIgnoreCase(final String target1, final String target2)
starts With Ignore Case
if (target1 == null || target2 == null) {
    return false;
int length1 = target1.length();
int length2 = target2.length();
if (length1 < length2) {
    return false;
String s1 = target1.substring(0, target2.length());
return s1.equalsIgnoreCase(target2);
booleanstartsWithIgnoreCase(final String text, final String prefix)
Tests if the string starts with the specified prefix.
if (isEmpty(text)) {
    return false;
if (prefix == null) {
    return false;
int textLength = text.length();
int prefixLength = prefix.length();
...
booleanstartsWithIgnoreCase(final String text, final String prefix)
Tests if the string starts with the specified prefix.
if (text == null || prefix == null) {
    return false;
return text.regionMatches(true, 0, prefix, 0, prefix.length());
booleanstartsWithIgnoreCase(final String value, final String possiblePrefix)
starts With Ignore Case
if (value == null || possiblePrefix == null || value.length() < possiblePrefix.length()) {
    return false;
return value.substring(0, possiblePrefix.length()).equalsIgnoreCase(possiblePrefix);
booleanstartsWithIgnoreCase(String a, String b)
Returns true if a starts with b regardless of the case.
return a.regionMatches(true, 0, b, 0, b.length());
booleanstartsWithIgnoreCase(String baseString, String compareString)
startWith
if (baseString == null || compareString == null)
    return false;
else
    return baseString.toUpperCase().startsWith(compareString.toUpperCase());
booleanstartsWithIgnoreCase(String haystack, String needle)
starts With Ignore Case
if (haystack.length() < needle.length()) {
    return false;
for (int i = 0; i < needle.length(); i++) {
    if (Character.toLowerCase(haystack.charAt(i)) != needle.charAt(i)) {
        return false;
return true;