Java Utililty Methods String Camel Case to Upper Case

List of utility methods to do String Camel Case to Upper Case

Description

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

Method

StringcamelCaseToUpperCase(final String camelCase)
camel Case To Upper Case
StringBuffer result = new StringBuffer();
boolean lastWasNotUpperCase = false;
for (int chI = 0; chI < camelCase.length(); chI++) {
    char ch = camelCase.charAt(chI);
    if (Character.isUpperCase(ch)) {
        if (lastWasNotUpperCase) {
            result.append("_");
        lastWasNotUpperCase = false;
    } else {
        lastWasNotUpperCase = true;
    result.append(Character.toUpperCase(ch));
return result.toString();
StringcamelCaseToUpperCase(String camelCaseName)
camel Case To Upper Case
StringBuilder upperCaseName = new StringBuilder();
boolean prevCharIsNumber = false;
for (int i = 0; i < camelCaseName.length(); i++) {
    char c = camelCaseName.charAt(i);
    if (i > 0 && c >= 'A' && c <= 'Z') {
        upperCaseName.append("_").append(c);
        prevCharIsNumber = false;
    } else if (c >= '0' && c <= '9') {
...
StringcamelCaseToUpperCase(String in)
camel Case To Upper Case
String regex = "([a-z])([A-Z])";
String replacement = "$1_$2";
String out = in.replaceAll(regex, replacement).toUpperCase();
return out;
StringcamelToUpper(String camel)
Convert CamelCase strings to ALL_UPPERCASE_WITH_UNDERSCORES.
return camel.replaceAll("([A-Z][a-z0-9])", "_$1").substring(1).toUpperCase();
StringcamelToUpper(String name)
Converts a camelCase name into an upper-case underscore-separated name.
StringBuilder buf = new StringBuilder();
for (int i = 0; i < name.length(); i++) {
    char c = name.charAt(i);
    if (Character.isUpperCase(c)) {
        buf.append('_');
    } else {
        c = Character.toUpperCase(c);
    buf.append(c);
return buf.toString();
StringcamelToUpper(String s)
Converts a camel-case name to an upper-case name with underscores.
StringBuilder buf = new StringBuilder(s.length() + 10);
int prevUpper = -1;
for (int i = 0; i < s.length(); ++i) {
    char c = s.charAt(i);
    if (Character.isUpperCase(c)) {
        if (i > prevUpper + 1) {
            buf.append('_');
        prevUpper = i;
    } else {
        c = Character.toUpperCase(c);
    buf.append(c);
return buf.toString();