Java Utililty Methods String Capitalize First

List of utility methods to do String Capitalize First

Description

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

Method

StringcapitalizeFirstLetter(String s)
capitalize First Letter
return s.substring(0, 1).toUpperCase() + s.substring(1);
StringcapitalizeFirstLetter(String s)
capitalize First Letter
if (s.length() == 0)
    throw new IllegalArgumentException("Cannot capitalize first letter of empty string");
return Character.toString(Character.toUpperCase(s.charAt(0))) + s.substring(1);
StringcapitalizeFirstLetter(String str)
capitalize First Letter
char[] chars = str.toCharArray();
if ((chars[0] >= 97 && chars[0] <= 122)) {
    chars[0] -= 32;
return String.valueOf(chars);
StringcapitalizeFirstLetter(String str)
Capitalize the first letter in a word
if (str.length() == 0) {
    return str;
} else if (str.length() == 1) {
    return str.toUpperCase();
char[] string = str.toLowerCase().toCharArray();
string[0] = Character.toUpperCase(string[0]);
for (int index = 0; index < string.length; index++) {
...
StringcapitalizeFirstLetter(String str)
capitalizes just the first letter and returns the given string
if (str == null)
    return null;
if (str.length() == 0)
    return str;
if (str.length() == 1)
    return Character.toString((Character.toUpperCase(str.charAt(0))));
else
    return Character.toUpperCase(str.charAt(0)) + str.substring(1);
...
StringcapitalizeFirstLetter(String str)
capitalize First Letter
if (str != null && str.length() == 1) {
    return String.valueOf(str.charAt(0)).toUpperCase();
} else if (str != null && str.length() > 1) {
    return String.valueOf(str.charAt(0)).toUpperCase() + str.substring(1);
} else
    return str;
StringcapitalizeFirstLetter(String str)
Makes the first letter uppercase of the given String.
if (str == null || str.length() == 0) {
    return str;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Character.toTitleCase(str.charAt(0)));
if (str.length() > 1) {
    stringBuilder.append(str.substring(1));
return stringBuilder.toString();
StringcapitalizeFirstLetter(String str)
capitalize First Letter
return (isEmpty(str) || !Character.isLetter(str.charAt(0))) ? str
        : Character.toUpperCase(str.charAt(0)) + str.substring(1);
StringcapitalizeFirstLetter(String str)
Returns a new string where the first letter of the specified string is capitalized.
if (str.length() > 0) {
    return replaceCharAt(str, 0, Character.toUpperCase(str.charAt(0)));
return str;
StringcapitalizeFirstLetter(String string)
Given a string, returns a new String with the first letter, and only the first letter, capitalized.
String lowerCaseString = string.toLowerCase();
return Character.toUpperCase(lowerCaseString.charAt(0)) + lowerCaseString.substring(1);