Java Utililty Methods String Title Case

List of utility methods to do String Title Case

Description

The list of methods to do String Title Case are organized into topic(s).

Method

Stringtitlecase(String str)
titlecase
return (Character.toTitleCase(str.charAt(0)) + str.substring(1));
StringtitleCase(String txt)
Convert the first character and every character that follows a space to uppercase.
StringBuffer buf = new StringBuffer(txt);
int len = buf.length();
buf.setCharAt(0, Character.toUpperCase(buf.charAt(0)));
for (int i = 1; i < len; i++) {
    if (buf.charAt(i - 1) == ' ') {
        buf.setCharAt(i, Character.toUpperCase(buf.charAt(i)));
return buf.toString();
StringtitleCasedName(T instance)
title Cased Name
StringBuilder name = new StringBuilder(instance.name().toLowerCase());
name.setCharAt(0, Character.toUpperCase(name.charAt(0)));
for (int i = 0; i < name.length(); i++) {
    if (name.charAt(i) == '_') {
        name.setCharAt(i, ' ');
        name.setCharAt(i + 1, Character.toUpperCase(name.charAt(i + 1)));
return name.toString();
StringtitleCaseTruncate(String s, int maxlen)
title Case Truncate
return transform(s, true, false, maxlen);
inttoTitleCase(final int chr)
Convert a character to title case
return Character.toTitleCase(chr);
StringtoTitleCase(final String input)
Capitalizes all words in a string.
if (input == null || input.isEmpty())
    throw new IllegalArgumentException("Input cannot be null or empty!");
final String[] words = input.trim().split(" ");
final StringBuilder sb = new StringBuilder();
for (final String word : words) {
    sb.append(Character.toUpperCase(word.charAt(0))).append(word.substring(1)).append(' ');
return sb.toString().trim();
...
StringtoTitleCase(final String inStr)
Converts the string to title case.
if ((inStr == null) || (inStr.length() < 1)) {
    return "";
} else {
    final int nLen = inStr.length();
    if (nLen == 1) {
        return inStr.toUpperCase();
    boolean blankFound = true;
...
StringtoTitleCase(final String inStr, final boolean putRestInLC)
Convert a string to title case.
if ((inStr == null) || (inStr.length() < 1)) {
    return "";
} else {
    final int nLen = inStr.length();
    if (nLen == 1) {
        return inStr.toUpperCase();
    boolean blankFound = true;
...
StringtoTitleCase(final String s)
Converts an input string into title case, capitalizing the first character of every word.
final StringBuilder sb = new StringBuilder(s);
return toTitleCase(sb).toString();
StringtoTitleCase(final String text)
to Title Case
if (text == null) {
    return null;
if ("".equals(text)) {
    return "";
return text.substring(0, 1).toUpperCase() + text.substring(1);