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

StringcapitalizeFirst(String name)
capitalize First
char first = name.charAt(0);
first = Character.toUpperCase(first);
StringBuffer newName = new StringBuffer(name);
newName.setCharAt(0, first);
return newName.toString();
StringcapitalizeFirst(String rawStr)
capitalize First
String str = rawStr.trim();
char[] chars = str.toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
return String.valueOf(chars);
StringcapitalizeFirst(String s)
Returns the specified string, with the first character capitalized.
if (s == null) {
    return null;
} else if (s.isEmpty()) {
    return s;
} else {
    return Character.toUpperCase(s.charAt(0)) + s.substring(1);
StringcapitalizeFirst(String str)
capitalize First
if (str == null || str.isEmpty())
    return str;
final char[] arr = str.toCharArray();
final char c = arr[0];
if (Character.isLetter(c))
    arr[0] = Character.toUpperCase(c);
return arr.toString();
StringcapitalizeFirst(String str)
Capitalize the first letter of the string and lowercase the rest of the string.
return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase();
StringcapitalizeFirst(String str)
Capitalizes the first letter of a string, and returns the result.
(Based on ucfirst() function of PHP)
str = str.trim();
if (str.length() > 0 && Character.isLetter(str.charAt(0)))
    return str.substring(0, 1).toUpperCase() + str.substring(1);
return str;
StringcapitalizeFirst(String str)
capitalize First
if (str.isEmpty()) {
    return str;
char firstCh = str.charAt(0);
char newFirstCh = Character.toUpperCase(firstCh);
if (firstCh == newFirstCh) {
    return str;
return newFirstCh + str.substring(1);
StringcapitalizeFirst(String str)
Convert the first character in a string to uppercase.
if (str.length() == 0)
    return str;
return str.substring(0, 1).toUpperCase() + str.substring(1);
StringcapitalizeFirst(String str)
capitalize First
if (str == null)
    return null;
if (str.length() > 1) {
    return str.substring(0, 1).toUpperCase() + str.substring(1);
} else if (str.length() == 1) {
    return str.toUpperCase();
} else {
    return str;
...
StringcapitalizeFirst(String string)
Capitalize the first letter of the given string
if (string != null) {
    return (string.substring(0, 1).toUpperCase() + string.substring(1, string.length()));
} else {
    return "";