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

StringcamelCase2UnderScoreCase(String str)
camel Case Under Score Case
StringBuilder sb = new StringBuilder();
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
    char c = chars[i];
    if (Character.isUpperCase(c)) {
        sb.append("_").append(Character.toLowerCase(c));
    } else {
        sb.append(c);
...
StringcamelCase2UnderscoreLowercase(String name)
camel Case Underscore Lowercase
return camelCase2Underscore(name).toLowerCase().replace('-', '_');
StringcamelCaseToLowerCaseUnderline(String name)
camel Case To Lower Case Underline
StringBuilder newName = new StringBuilder();
for (int i = 0; i < name.length(); i++)
    if (Character.isUpperCase(name.charAt(i))) {
        if (i == 0)
            newName.append(Character.toLowerCase(name.charAt(i)));
        else
            newName.append("_").append(Character.toLowerCase(name.charAt(i)));
    } else
...
StringcamelCaseToUnderline(String name)
camel Case To Underline
final int length = name.length();
boolean inupper = false;
StringBuilder stb = new StringBuilder(length);
int i = 0;
while (i < length) {
    char c = name.charAt(i);
    i = i + 1;
    if (inupper) {
...
StringcamelCaseToUnderscore(final String camelCaseString)
Convert aStringUnderscored into A_STRING_UNDESCORED.
StringBuilder sb = new StringBuilder();
for (String camelPart : camelCaseString.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])")) {
    if (sb.length() > 0) {
        sb.append("_");
    sb.append(camelPart.toUpperCase());
return sb.toString();
...
StringcamelCaseToUnderscore(final String str)
camel Case To Underscore
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    if (Character.isUpperCase(c)) {
        if (i != 0) {
            sb.append("_");
        sb.append(Character.toLowerCase(c));
...
StringcamelCaseToUnderscore(String camelCase)
Turns CamelCased string into Underscored one
StringBuilder builder = new StringBuilder();
char[] chars = camelCase.toCharArray();
for (int j = 0; j < chars.length; j++) {
    if (Character.isUpperCase(chars[j])) {
        if (j != 0) {
            builder.append('_');
        builder.append(Character.toLowerCase(chars[j]));
...
StringcamelCaseToUnderscore(String camelCased)
camel Case To Underscore
final String regex = "([a-z])([A-Z]+)";
final String replacement = "$1_$2";
return camelCased.replaceAll(regex, replacement);
StringcamelCaseToUnderScore(String key)
camel Case To Under Score
if (key.isEmpty())
    return key;
StringBuilder sb = new StringBuilder(key.length());
for (int i = 0; i < key.length(); i++) {
    char c = key.charAt(i);
    if (Character.isUpperCase(c))
        sb.append("_").append(Character.toLowerCase(c));
    else
...
StringcamelCaseToUnderscored(String camelCaseName)
A deliberately very inflexible camel case to underscored converter; it must not convert improper camel case names to a proper underscored name.
int i = 0;
while (i < camelCaseName.length() && Character.isLowerCase(camelCaseName.charAt(i))) {
    i++;
if (i == camelCaseName.length()) {
    return camelCaseName;
StringBuffer sb = new StringBuffer();
...