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(final String input)
title Case
if (input.contains(" ")) {
    final String[] strings = input.split(" ");
    final StringBuilder sb = new StringBuilder();
    for (final String s : strings) {
        sb.append(s.substring(0, 1).toUpperCase()).append(s.substring(1).toLowerCase()).append(" ");
    return sb.toString();
return input.substring(0, 1).toUpperCase() + input.substring(1).toLowerCase();
StringtitleCase(final String s)
title Case
if (s == null || s.length() == 0) {
    return s;
} else if (s.length() == 1) {
    return s.toUpperCase();
} else {
    StringBuilder result = new StringBuilder(s.length());
    String delim = "";
    for (String eachPart : s.split(" ")) {
...
StringtitleCase(final String text)
title Case
if (text == null) {
    throw new IllegalArgumentException("text");
return text.substring(0, 1).toUpperCase().concat(text.substring(1));
StringtitleCase(String in)
title Case
StringBuilder sb = new StringBuilder(in);
boolean cap = true;
for (int i = 0; i < sb.length(); i++) {
    char ch = sb.charAt(i);
    if (ch == '_') {
        sb.setCharAt(i, ' ');
        cap = true;
        continue;
...
StringtitleCase(String input)
title Case
return input.substring(0, 1).toUpperCase() + input.substring(1);
StringtitleCase(String name)
Return the string in Titlecase, i.e.
if (name.length() == 0)
    return name;
return Character.toUpperCase(name.charAt(0)) + name.substring(1);
StringtitleCase(String raw)
Returns a TitleCase version of the String supplied
String s = raw;
if (s != null) {
    if (s.length() > 1) {
        s = s.substring(0, 1).toUpperCase() + s.substring(1);
    } else if (s.length() == 1) {
        s = s.toUpperCase();
return s;
StringtitleCase(String realName)
title Case
String space = " ";
String[] names = realName.split(space);
StringBuilder b = new StringBuilder();
for (String name : names) {
    if (name == null || name.isEmpty()) {
        b.append(space);
        continue;
    b.append(name.substring(0, 1).toUpperCase()).append(name.substring(1).toLowerCase()).append(space);
return b.toString();
StringtitleCase(String s)
Returns a title case version of the String.
if (s.length() > 1) {
    return s.substring(0, 1).toUpperCase() + s.substring(1);
return s.toUpperCase();
StringtitleCase(String str)
title Case
StringBuilder ret = new StringBuilder();
boolean st = true;
for (char c : str.toLowerCase().toCharArray()) {
    if (st) {
        ret.append(Character.toTitleCase(c));
    } else {
        ret.append(c);
    st = c == ' ';
return ret.toString();