Java Utililty Methods String Snake Case

List of utility methods to do String Snake Case

Description

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

Method

StringtoSnakeCase(String camelCase)
to Snake Case
if (camelCase == null) {
    throw new NullPointerException();
String[] parts = camelCase.split(SNAKE_CASE_SPLIT_REGEX);
StringBuilder builder = new StringBuilder(camelCase.length() + (parts.length - 1));
for (int i = 0; i < parts.length - 1; i++) {
    builder.append(parts[i].toLowerCase()).append('_');
builder.append(parts[parts.length - 1].toLowerCase());
return builder.toString();
StringtoSnakeCase(String s)
to Snake Case
return s.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase();
StringtoSnakeCase(String src)
to Snake Case
String dst = new String();
for (int i = 0; i < src.length(); i++) {
    char c = src.charAt(i);
    if ('A' <= c && c <= 'Z') {
        c += 32;
        if (i != 0) {
            dst += '_';
    dst += c;
return dst;
StringtoSnakeCase(String str)
Convert a string to snake_case
return str.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase();
StringtoSnakeCase(String str)
Transforms a string to underscore-delimited representation.
StringBuilder sb = new StringBuilder();
for (char c : str.toCharArray()) {
    if (Character.isLetter(c) || Character.isDigit(c)) {
        if (Character.isUpperCase(c)) {
            if (sb.length() > 0) {
                sb.append("_");
            sb.append(Character.toLowerCase(c));
...
StringtoSnakeCase(String str, boolean capitalize, Boolean upper)
to Snake Case
return changeSeparator(str, '_', capitalize, null, upper);