Java String Camel Case to Underscore camelCase2UnderScoreCase(String str)

Here you can find the source of camelCase2UnderScoreCase(String str)

Description

camel Case Under Score Case

License

Open Source License

Declaration

public static final String camelCase2UnderScoreCase(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static final String camelCase2UnderScoreCase(String str) {
        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);/*from   w  w  w  .  j a va2 s .com*/
            }
        }
        return sb.toString();
    }

    public static String toString(Object object) {
        return toString(object, null);
    }

    public static String toString(Object object, String defaultValue) {
        if (object == null)
            return defaultValue;
        return String.valueOf(object);
    }
}

Related

  1. camelCase2UnderscoreLowercase(String name)
  2. camelCaseToLowerCaseUnderline(String name)
  3. camelCaseToUnderline(String name)
  4. camelCaseToUnderscore(final String camelCaseString)