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

StringcamelString(String str, boolean firstCharacterUppercase)
camel String
if (str == null) {
    return null;
StringBuffer sb = new StringBuffer();
boolean nextUpperCase = false;
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    if (isWordSeparator(c)) {
...
StringfirstByteToLower(String instring)
first Byte To Lower
return instring.substring(0, 1).toLowerCase()
        + instring.substring(1, instring.length());
Stringcapitalize(String plainMessage, char letter)
Replace all occurrences of letter in plainMessage with toUpperCase(letter)
StringBuffer message = new StringBuffer(plainMessage);
for (int i = 0; i < plainMessage.length(); i++) {
    char c = plainMessage.charAt(i);
    if (Character.isLetter(c)) {
        if (Character.toUpperCase(c) == Character
                .toUpperCase(letter)) {
            message.setCharAt(i, Character.toUpperCase(c));
return message.toString();
Stringuncapitalize(String capitalizedMessage, char letter)
Replace all occurrences of letter in capitalizedMessage with toLowerCase(letter)
StringBuffer message = new StringBuffer(capitalizedMessage);
for (int i = 0; i < message.length(); i++) {
    char c = message.charAt(i);
    if (Character.isLetter(c)) {
        if (Character.toLowerCase(c) == Character
                .toLowerCase(letter)) {
            message.setCharAt(i, Character.toLowerCase(c));
return message.toString();
chartoUpper(char ch)
to Upper
if (inRange11(ch, 'a', 'z')) {
    return (char) (ch - 'a' + 'A');
return ch;
StringtoLowerSubset(String source, char substitute)
Returns a string with non alphanumeric chars converted to the substitute character.
int len = source.length();
StringBuffer sb = new StringBuffer(len);
char ch;
for (int i = 0; i < len; i++) {
    ch = source.charAt(i);
    if (!Character.isLetterOrDigit(ch)) {
        sb.append(substitute);
    } else if ((i == 0) && Character.isDigit(ch)) {
...
StringUpperCase(String str)
Upper Case
int len = str.length();
String result = "";
for (int i = 0; i < len; i++) {
    String subStr = str.substring(i, i + 1);
    char subChar = str.charAt(i);
    if (subChar >= 'a' && subChar <= 'z')
        result += subStr.toUpperCase();
    else
...
Stringcapitalize(String s)
capitalize
if (s == null || s.length() == 0) {
    return "";
char first = s.charAt(0);
if (Character.isUpperCase(first)) {
    return s;
} else {
    return Character.toUpperCase(first) + s.substring(1);
...
Stringcapitalize(final String str)
capitalize
final char[] buffer = str.toCharArray();
boolean capitalizeNext = true;
for (int i = 0; i < buffer.length; i++) {
    final char ch = buffer[i];
    if (capitalizeNext) {
        buffer[i] = Character.toTitleCase(ch);
        capitalizeNext = false;
return new String(buffer);
CharSequencecapitalizeFirst(CharSequence movementTitle)
capitalize First
if (TextUtils.isEmpty(movementTitle))
    return movementTitle;
return String.valueOf(movementTitle.charAt(0)).toUpperCase(
        Locale.ENGLISH)
        + movementTitle.toString().substring(1)
                .toLowerCase(Locale.ENGLISH);