Java Utililty Methods String Camel Case to Underscore

List of utility methods to do String Camel Case to Underscore

Description

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

Method

StringcamelCaseToUnderscores(String camel)
camel Case To Underscores
String underscore;
underscore = String.valueOf(Character.toLowerCase(camel.charAt(0)));
for (int i = 1; i < camel.length(); i++) {
    underscore += Character.isLowerCase(camel.charAt(i)) ? String.valueOf(camel.charAt(i))
            : "_" + String.valueOf(Character.toLowerCase(camel.charAt(i)));
return underscore;
StringcamelCaseToUnderScoreUpperCase(String camelCase)
Convert a camel case string to underscored capitalized string.
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)
...
StringcamelToUnder(String value)
convierte el string value de formato camelcase to underscore
String regex = "([a-z])([A-Z])";
String replacement = "$1_$2";
return value.replaceAll(regex, replacement).toLowerCase();
StringcamelToUnderline(String param)
camel To Underline
if (param == null || param.length() == 0) {
    return param;
int len = param.length();
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++) {
    char c = param.charAt(i);
    if (Character.isUpperCase(c)) {
...
StringcamelToUnderlinedName(String name)
camel To Underlined Name
StringBuilder sb = new StringBuilder();
boolean lastWasUnderline = false;
for (int i = 0; i < name.length(); i++) {
    char c = name.charAt(i);
    boolean isCaps = Character.isUpperCase(c);
    if (isCaps) {
        if (i > 0 && !lastWasUnderline) {
            sb.append('_');
...
StringcamelToUnderLineString(String str)
null => "" " " => "" "abc" => "abc" "aBc" => "a_bc" "helloWord" => "hello_word" "hi hao are you" => "hi hao are you" "helloWord_iAmHsl" => "hello_word_i_am_hsl"
return camelToFixedString(str, "_");
StringcamelToUnderscore(String value)
Convert a string from camel case to underscores, also replacing periods with underscores (so for example a fully qualified Java class name gets underscores everywhere).
String result = value.replace(" ", "_");
result = result.replaceAll("([a-z])([A-Z])", "$1_$2");
result = result.replace(".", "_");
result = result.toLowerCase();
return result;