The accepted answer is wrong. If you look at the implementation of String.equalsIgnoreCase()
you will discover that you need to compare both lowercase and uppercase versions of the Strings before you can conclusively return false
.
Here is my own version, based on http://www.java2s.com/Code/Java/Data-Type/CaseinsensitivecheckifaStringstartswithaspecifiedprefix.htm:
/**
* String helper functions.
*
* @author Gili Tzabari
*/
public final class Strings
{
/**
* @param str a String
* @param prefix a prefix
* @return true if {@code start} starts with {@code prefix}, disregarding case sensitivity
*/
public static boolean startsWithIgnoreCase(String str, String prefix)
{
return str.regionMatches(true, 0, prefix, 0, prefix.length());
}
public static boolean endsWithIgnoreCase(String str, String suffix)
{
int suffixLength = suffix.length();
return str.regionMatches(true, str.length() - suffixLength, suffix, 0, suffixLength);
}
/**
* Prevent construction.
*/
private Strings()
{
}
}