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
if (isAlpha(str.charAt(0))) {
    return str.substring(0, 1).toUpperCase() + str.substring(1);
} else
    return str.charAt(0) + str.substring(1, 2).toUpperCase() + str.substring(2);
Stringcapitalize(String str)
capitalize
String[] parts = str.toLowerCase().split(" ");
StringBuilder buf = new StringBuilder();
for (String part : parts) {
    buf.append(part.substring(0, 1).toUpperCase() + part.substring(1) + " ");
if (buf.length() > 1) {
    return buf.toString().trim();
} else {
...
Stringcapitalize(String str)
Capitalizes the first character of the given String.
if (str == null || str.length() < 1)
    return str;
return str.substring(0, 1).toUpperCase() + str.substring(1);
Stringcapitalize(String str)

Capitalizes all the whitespace separated words in a String.

return capitalize(str, null);
Stringcapitalize(String str)
capitalize
StringBuilder sb = new StringBuilder(str);
String firstChar = sb.substring(0, 1);
String upperFirstChar = firstChar.toUpperCase();
sb.delete(0, 1);
sb.insert(0, upperFirstChar);
return sb.toString();
Stringcapitalize(String str)
capitalize
if (str == null || str.length() == 0) {
    return str;
StringBuilder sb = new StringBuilder(str.length());
sb.append(Character.toUpperCase(str.charAt(0)));
sb.append(str.toLowerCase().substring(1));
return sb.toString();
Stringcapitalize(String str)

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

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 capitalized = str;
if (str == null || str.isEmpty()) {
    return capitalized;
capitalized = String.valueOf(str.charAt(0)).toUpperCase() + str.substring(1);
return capitalized;
Stringcapitalize(String str)
capitalize
return changeFirstCharacterCase(str, true);
Stringcapitalize(String str)
Capitalize a String , changing the first letter to upper case as per Character#toUpperCase(char) .
return changeFirstCharacterCase(str, true);