Android Utililty Methods String Case Convert

List of utility methods to do String Case Convert

Description

The list of methods to do String Case Convert are organized into topic(s).

Method

StringtoLowerCase(String src)
Safely convert the string to lowercase.
if (src == null) {
    return null;
} else {
    return src.toLowerCase();
StringtoUpperCase(String src)
Safely convert the string to uppercase.
if (src == null) {
    return null;
} else {
    return src.toUpperCase();
StringflipCase(final String s)
flip Case
final StringBuilder builder = new StringBuilder(s);
for (int i = 0; i < s.length(); ++i) {
    char c = builder.charAt(i);
    if (Character.isUpperCase(c)) {
        c = Character.toLowerCase(c);
    } else if (Character.isLowerCase(c)) {
        c = Character.toUpperCase(c);
    builder.setCharAt(i, c);
return builder.toString();
booleanmatchesIgnoreCase(String str, String query, int startingAt)
matches Ignore Case
int len = query.length();
for (int i = 0; i < len; i++) {
    if (Character.toUpperCase(query.charAt(i)) != Character
            .toUpperCase(str.charAt(startingAt + i))) {
        return false;
return true;
...
StringlowerCase(String str)
lower Case
if (str == null) {
    return null;
return str.toLowerCase();
StringupperCase(String str)
upper Case
if (str == null) {
    return null;
return str.toUpperCase();
booleanendsWithIgnoreCase(String source, String suffix)
Whether the given source string ends with the given suffix, ignoring case.
if (isEmpty(suffix))
    return true;
if (isEmpty(source))
    return false;
if (suffix.length() > source.length())
    return false;
return source.substring(source.length() - suffix.length())
        .toLowerCase().endsWith(suffix.toLowerCase());
...
booleanendsWithIgnoreCase(final String target1, final String target2)
ends 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(length1 - length2);
return s1.equalsIgnoreCase(target2);
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);
StringtoTitleCase(String s)
Converts a string into title case.
StringBuilder titleCase = new StringBuilder();
boolean nextTitleCase = true;
for (char c : s.toCharArray()) {
    if (Character.isSpaceChar(c)) {
        nextTitleCase = true;
    } else if (nextTitleCase) {
        c = Character.toTitleCase(c);
        nextTitleCase = false;
...