Java String Title Case titleCasedName(T instance)

Here you can find the source of titleCasedName(T instance)

Description

title Cased Name

License

BSD License

Declaration

public static <T extends Enum<T>> String titleCasedName(T instance) 

Method Source Code

//package com.java2s;
/*//from w ww . ja  v  a2  s.co  m
 * Copyright Northwestern University and SemanticBits, LLC
 * 
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/ctms-commons/LICENSE.txt for details.
 */

public class Main {
    public static <T extends Enum<T>> String titleCasedName(T instance) {
        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();
    }
}

Related

  1. titleCase(String realName)
  2. titleCase(String s)
  3. titleCase(String str)
  4. titlecase(String str)
  5. titleCase(String txt)
  6. titleCaseTruncate(String s, int maxlen)
  7. toTitleCase(final int chr)
  8. toTitleCase(final String input)
  9. toTitleCase(final String inStr)