Java Utililty Methods String Capitalize

List of utility methods to do String Capitalize

Description

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

Method

Stringcapitalize(String str)
capitalize
int strLen;
if (str != null && (strLen = str.length()) != 0) {
    char firstChar = str.charAt(0);
    return Character.isTitleCase(firstChar) ? str
            : (new StringBuilder(strLen)).append(Character.toTitleCase(firstChar)).append(str.substring(1))
                    .toString();
} else {
    return str;
...
Stringcapitalize(String str)
Capitalize a String , changing the first letter to upper case as per Character#toUpperCase(char) .
return changeFirstCharacterCase(str, true);
Stringcapitalize(String str)
capitalize
int strLen;
if (str == null || (strLen = str.length()) == 0) {
    return str;
return new StringBuffer(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1))
        .toString();
Stringcapitalize(String str)
capitalize
String prefix = str.substring(0, 1).toUpperCase();
String suffix = str.length() > 1 ? str.substring(1).toLowerCase() : "";
return prefix + suffix;
Stringcapitalize(String str)

Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .

if (str == null) {
    return null;
StringBuilder result = new StringBuilder(str.toString());
if (result.length() > 0) {
    result.setCharAt(0, Character.toTitleCase(result.charAt(0)));
return result.toString();
...
Stringcapitalize(String str)
capitalize
if (str == null || str.equals(""))
    return str;
return str.substring(0, 1).toUpperCase() + str.substring(1);
Stringcapitalize(String str)
capitalize
if (str.isEmpty())
    return str;
return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase();
Stringcapitalize(String str)

Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .

String capilizedStr = str;
int len;
if (str != null && (len = str.length()) > 0) {
    capilizedStr = new StringBuilder(len).append(Character.toTitleCase(str.charAt(0)))
            .append(str.substring(1)).toString();
return capilizedStr;
Stringcapitalize(String str)
Borrowed from commons-lang StringUtils.capitalize() method.
int strLen;
if (str == null || (strLen = str.length()) == 0) {
    return str;
return new StringBuffer(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1))
        .toString();
Stringcapitalize(String str)
capitalize
int strLen;
if (str == null || (strLen = str.length()) == 0) {
    return str;
return new StringBuilder(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1))
        .toString();