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(final String s)
capitalize First Letter
final char[] first = s.toCharArray();
if (Character.isLetter(first[0])) {
    first[0] = Character.toUpperCase(first[0]);
    return new String(first);
return s;
StringcapitalizeFirstLetter(final String variableName)
Returns the String passed in with the first letter capitalised.
return variableName.substring(0, 1).toUpperCase() + variableName.substring(1);
StringcapitalizeFirstLetter(String data)
capitalize First Letter
char firstLetter = Character.toTitleCase(data.substring(0, 1).charAt(0));
String restLetters = data.substring(1);
return firstLetter + restLetters;
StringcapitalizeFirstLetter(String data)

Capitalize the first letter but leave the rest as they are.

String firstLetter = data.substring(0, 1).toUpperCase();
String restLetters = data.substring(1);
return firstLetter + restLetters;
StringcapitalizeFirstLetter(String data)
capitalize First Letter
char firstChar = data.charAt(0);
char titleCase = Character.toTitleCase(firstChar);
if (firstChar == titleCase) {
    return data;
StringBuilder result = new StringBuilder(data.length());
result.append(titleCase);
result.append(data, 1, data.length());
...
StringcapitalizeFirstLetter(String message)
Capitalizes the first letter of the message and returns the result.
if (message == null || message.length() == 0) {
    return message;
char firstUpperCaseLetter = Character.toUpperCase(message.charAt(0));
String remainderOfMessage = message.substring(1);
return firstUpperCaseLetter + remainderOfMessage;
StringCapitalizeFirstLetter(String name)
Capitalize First Letter
if (name == null)
    return null;
String firstLetter = name.substring(0, 1);
String remainder = name.substring(1);
String capitalized = firstLetter.toUpperCase() + remainder.toLowerCase();
return capitalized;
StringcapitalizeFirstLetter(String s)
Capitalize first letter in string.
char[] chars = s.toLowerCase().toCharArray();
for (int i = 0; i < chars.length; i++) {
    char ch = chars[i];
    if (Character.isLetter(ch)) {
        chars[i] = Character.toUpperCase(ch);
        break;
return new String(chars);
StringcapitalizeFirstLetter(String s)
Capitalizes the first letter of the given String.
char[] chars = s.toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
return new String(chars);
StringcapitalizeFirstLetter(String s)
capitalize First Letter
if (s == null || s.isEmpty())
    return s;
return s.length() == 1 ? s.toUpperCase() : s.substring(0, 1).toUpperCase() + s.substring(1);