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 string)
Capitalizes the string correctly.
boolean capitalize = true;
StringBuilder builder = new StringBuilder(string);
int length = string.length();
for (int index = 0; index < length; index++) {
    char character = builder.charAt(index);
    if (character == '.' || character == '!' || character == '?') {
        capitalize = true;
    } else if (capitalize && !Character.isWhitespace(character)) {
...
Stringcapitalize(String string)
capitalize
return isNotEmpty(string) ? string.substring(0, 1).toUpperCase() + string.substring(1) : string;
Stringcapitalize(String string)
Convert the first character to uppercase, and all remaining characters to lowercase.
if (string != null && string.length() > 0) {
    if (string.length() == 1) {
        return string.toUpperCase();
    return string.substring(0, 1).toUpperCase() + string.substring(1).toLowerCase();
return string;
Stringcapitalize(String string)
capitalize
String[] nameList = string.toLowerCase().replace("_", " ").replace("-", " ").split(" ");
String name = "";
for (String word : nameList) {
    name = name + word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase() + " ";
if (name.endsWith(" "))
    name = name.substring(0, name.length() - 1);
return name;
...
Stringcapitalize(String string)
capitalize
char[] chars = string.toLowerCase().toCharArray();
boolean found = false;
for (int i = 0; i < chars.length; i++) {
    if (!found && Character.isLetter(chars[i])) {
        chars[i] = Character.toUpperCase(chars[i]);
        found = true;
    } else if (Character.isWhitespace(chars[i])) {
        found = false;
...
Stringcapitalize(String string)
capitalize
if (string.isEmpty()) {
    return string;
if (string.length() == 1) {
    return string.toUpperCase();
final String first = string.substring(0, 1);
final String remaining = string.substring(1);
...
Stringcapitalize(String string)
capitalize
return prepare(string, true);
Stringcapitalize(String string)
capitalize
if (string == null || string.trim().length() == 0) {
    return string;
String[] tokens = string.split("\\s");
string = "";
for (int i = 0; i < tokens.length; i++) {
    char capLetter = Character.toUpperCase(tokens[i].charAt(0));
    string += (i == 0 ? "" : " ") + capLetter + tokens[i].substring(1, tokens[i].length());
...
Stringcapitalize(String string)
capitalize
if (string == null)
    throw new NullPointerException("string is null");
if (string.length() == 0)
    throw new IllegalArgumentException("string is empty");
if (string.length() == 1) {
    return "" + Character.toUpperCase(string.charAt(0));
return Character.toUpperCase(string.charAt(0)) + string.substring(1);
...
Stringcapitalize(String string)
capitalize
if (isEmptyTrim(string)) {
    return string;
if (string.length() < 2) {
    return string.toUpperCase();
return Character.toUpperCase(string.charAt(0)) + string.substring(1).toLowerCase();