Java String Camel Case to Underscore camelCase2UnderscoreLowercase(String name)

Here you can find the source of camelCase2UnderscoreLowercase(String name)

Description

camel Case Underscore Lowercase

License

Apache License

Declaration

public static String camelCase2UnderscoreLowercase(String name) 

Method Source Code

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

public class Main {
    public static String camelCase2UnderscoreLowercase(String name) {
        return camelCase2Underscore(name).toLowerCase().replace('-', '_');
    }/*from   w  ww  .j av  a2  s  .c  o  m*/

    public static String camelCase2Underscore(String name) {
        return camelCase2Delimiter(name, '_');
    }

    private static String camelCase2Delimiter(String name, char delimiter) {
        if (name == null || !name.matches(".*[A-Z].*") || !name.matches(".*[a-z].*"))
            return name;

        String regex = "([a-zA-Z])([A-Z])";
        String replacement = "$1" + delimiter + "$2";

        return name.replaceAll(regex, replacement).replaceAll(regex, replacement);
    }
}

Related

  1. camelCase2UnderScoreCase(String str)
  2. camelCaseToLowerCaseUnderline(String name)
  3. camelCaseToUnderline(String name)
  4. camelCaseToUnderscore(final String camelCaseString)
  5. camelCaseToUnderscore(final String str)