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(final String s)
Capitalizes a string.
final char[] chars = s.toCharArray();
if (chars.length > 0) {
    chars[0] = Character.toUpperCase(chars[0]);
return new String(chars);
Stringcapitalize(final String str)

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

int strLen;
if (str == null || (strLen = str.length()) == 0) {
    return str;
final int firstCodepoint = str.codePointAt(0);
final int newCodePoint = Character.toTitleCase(firstCodepoint);
if (firstCodepoint == newCodePoint) {
    return str;
...
Stringcapitalize(final String str)
capitalize
final char firstChar = str.charAt(0);
final char newChar = Character.toUpperCase(firstChar);
if (firstChar == newChar) {
    return str;
char[] newChars = new char[str.length()];
newChars[0] = newChar;
str.getChars(1, str.length(), newChars, 1);
...
Stringcapitalize(final String str)
capitalize
String result = null;
if (str != null) {
    if (str.length() >= 2) {
        result = str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase();
    } else {
        result = str.toUpperCase();
return result;
Stringcapitalize(final String str)
capitalize
final char[] buffer = str.toLowerCase().replace('-', '_').toCharArray();
buffer[0] = Character.toTitleCase(buffer[0]);
return new String(buffer);
Stringcapitalize(final String str)
capitalize
final char charAt = str.charAt(0);
return Character.toUpperCase(charAt) + str.substring(1);
Stringcapitalize(final String str)

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

int strLen;
if (str == null || (strLen = str.length()) == 0) {
    return str;
final char firstChar = str.charAt(0);
if (Character.isUpperCase(firstChar)) {
    return str;
return new StringBuilder(strLen).append(Character.toUpperCase(firstChar)).append(str.substring(1))
        .toString();
Stringcapitalize(final String str)
 StringUtils.capitalize(null)  = null StringUtils.capitalize("")    = "" StringUtils.capitalize("cat") = "Cat" StringUtils.capitalize("cAt") = "CAt" 
int strLen;
if (str == null || (strLen = str.length()) == 0) {
    return str;
final char firstChar = str.charAt(0);
if (Character.isTitleCase(firstChar)) {
    return str;
return new StringBuilder(strLen).append(Character.toTitleCase(firstChar)).append(str.substring(1))
        .toString();
Stringcapitalize(final String str)
Put first letter into uppercase
if (str.length() > 1) {
    return str.substring(0, 1).toUpperCase() + str.substring(1);
} else {
    return str.toUpperCase();
Stringcapitalize(final String str)
StringUtils.capitalize(null) = null StringUtils.capitalize("") = "" StringUtils.capitalize("cat") = "Cat" StringUtils.capitalize("cAt") = "CAt" StringUtils.capitalize("'cat'") = "'cat'"
int strLen;
if (str == null || (strLen = str.length()) == 0) {
    return str;
final char firstChar = str.charAt(0);
final char newChar = Character.toTitleCase(firstChar);
if (firstChar == newChar) {
    return str;
...