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)
capitalize
char begin = Character.toUpperCase(string.charAt(0));
if (string.length() == 1) {
    return Character.toString(begin);
} else {
    return begin + string.substring(1);
Stringcapitalize(String string)
capitalize
char[] letters = string.toCharArray();
for (int index = 0; index < letters.length; index++) {
    if (index != 0 && !Character.isWhitespace(letters[index - 1]))
        continue;
    if (!Character.isLowerCase(letters[index]))
        continue;
    letters[index] = Character.toUpperCase(letters[index]);
return new String(letters);
Stringcapitalize(String string, boolean firstWordOnly)
Capitalizes the first character in either the first word or all words in the given string.
if (string == null)
    return null;
char[] characters = string.toCharArray();
boolean capitalize = true;
for (int i = 0; i < characters.length; i++) {
    char character = characters[i];
    if (Character.isWhitespace(character)) {
        capitalize = true;
...
Stringcapitalize(String string, int index)
capitalize
if (index >= string.length() || index < 0) {
    throw new StringIndexOutOfBoundsException(index);
final StringBuilder stringBuilder = new StringBuilder(string.length());
if (index != 0) {
    stringBuilder.append(string, 0, index);
stringBuilder.append(Character.toUpperCase(string.charAt(index)));
...
Stringcapitalize(String string0)
Safely capitalizes a string by converting the first character to upper case.
if (string0 == null) {
    return null;
int length = string0.length();
if (length == 0) {
    return string0;
} else if (length == 1) {
    return string0.toUpperCase();
...
Stringcapitalize(String text)
Capitlize each word in a string (journal titles, etc)
StringBuilder resultText;
char previousC;
resultText = new StringBuilder();
previousC = '.';
for (int i = 0; i < text.length(); i++) {
    char c = text.charAt(i);
    if (Character.isLetter(c) && !Character.isLetter(previousC)) {
        resultText.append(Character.toUpperCase(c));
...
Stringcapitalize(String text)
capitalize
if (text != null && text != "") {
    return (text.substring(0, 1)).toUpperCase() + text.substring(1);
} else {
    return "";
Stringcapitalize(String text)
Capitalizes the text according to JavaBeans specification.
if (isEmpty(text)) {
    return text;
char chars[] = text.toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
return new String(chars);
Stringcapitalize(String text)
capitalize
char first = text.charAt(0);
if (Character.isUpperCase(first)) {
    return text;
first = Character.toUpperCase(first);
StringBuilder builder = new StringBuilder();
builder.append(first);
builder.append(text.substring(1));
...
Stringcapitalize(String text)
capitalize
StringBuilder cap = new StringBuilder();
text = text.replace("_", " ");
for (String t : text.split(" ")) {
    if (t.length() > 2) {
        cap.append(t.substring(0, 1).toUpperCase()).append(t.substring(1).toLowerCase()).append(" ");
    } else {
        cap.append(t).append(" ");
return cap.substring(0, cap.length() - 1);