Java String Camel Case to Underscore camelCaseToUnderScoreUpperCase(String camelCase)

Here you can find the source of camelCaseToUnderScoreUpperCase(String camelCase)

Description

Convert a camel case string to underscored capitalized string.

License

Apache License

Parameter

Parameter Description
camelCase a camel case string : only letters without consecutive uppercase letters.

Return

the transformed string or the same if not camel case.

Declaration

public static String camelCaseToUnderScoreUpperCase(String camelCase) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from  w  w  w  . j a  v  a  2 s . co m*/
     * Convert a camel case string to underscored capitalized string.
     * eg. thisIsStandardCamelCaseString is converted to THIS_IS_STANDARD_CAMEL_CASE_STRING
     * @param camelCase a camel case string : only letters without consecutive uppercase letters.
     * @return the transformed string or the same if not camel case.
     */
    public static String camelCaseToUnderScoreUpperCase(String camelCase) {
        String result = "";
        boolean prevUpperCase = false;
        for (int i = 0; i < camelCase.length(); i++) {
            char c = camelCase.charAt(i);
            if (!Character.isLetter(c))
                return camelCase;
            if (Character.isUpperCase(c)) {
                if (prevUpperCase)
                    return camelCase;
                result += "_" + c;
                prevUpperCase = true;
            } else {
                result += Character.toUpperCase(c);
                prevUpperCase = false;
            }
        }
        return result;
    }
}

Related

  1. camelCaseToUnderscore(String camelCase)
  2. camelCaseToUnderscore(String camelCased)
  3. camelCaseToUnderScore(String key)
  4. camelCaseToUnderscored(String camelCaseName)
  5. camelCaseToUnderscores(String camel)
  6. camelToUnder(String value)
  7. camelToUnderline(String param)
  8. camelToUnderlinedName(String name)
  9. camelToUnderLineString(String str)