Java String Camel Case To camel2underline(String s)

Here you can find the source of camel2underline(String s)

Description

camelunderline

License

Apache License

Declaration

public static String camel2underline(String s) 

Method Source Code

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

public class Main {

    public static String camel2underline(String s) {
        char c;/*w  ww  . j  a va2 s  .c o m*/
        int upperSize = 0;
        for (int i = 0; i < s.length(); i++) {
            c = s.charAt(i);
            if (Character.isUpperCase(c)) {
                upperSize++;
            }
        }
        if (upperSize == 0) {
            return s;
        }
        StringBuilder buf = new StringBuilder(s.length() + upperSize);
        for (int i = 0; i < s.length(); i++) {
            c = s.charAt(i);
            if (Character.isUpperCase(c)) {
                buf.append('_');
                buf.append(Character.toLowerCase(c));
            } else {
                buf.append(c);
            }
        }
        return buf.toString();
    }
}

Related

  1. camel2underline(String hump)
  2. camelCase2Delimiter(String name, char delimiter)
  3. camelCaseIt(String mappingName, String separator)
  4. camelCaseMatch(String word, String abbr)
  5. camelCaseNameToConstant(String camelCaseName)