Java String Underscore to underscore2camel(String underscoreName)

Here you can find the source of underscore2camel(String underscoreName)

Description

convert underscore name to camel name

License

Open Source License

Parameter

Parameter Description
underscoreName a parameter

Declaration

public static String underscore2camel(String underscoreName) 

Method Source Code

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

public class Main {
    /**//  w  w w .j a va 2  s. c o  m
     * convert underscore name to camel name
     * @param underscoreName
     * @return
     */
    public static String underscore2camel(String underscoreName) {
        String[] sections = underscoreName.split("_");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < sections.length; i++) {
            String s = sections[i];
            if (i == 0) {
                sb.append(s);
            } else {
                sb.append(capitalize(s));
            }
        }
        return sb.toString();
    }

    /**
     * capitalize the first character
     * @param str
     * @return
     */
    public static String capitalize(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }
        return new StringBuilder(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1))
                .toString();
    }
}

Related

  1. underScore2CamelCase(String strs)
  2. underscoreDashToCamelCase(String s)
  3. underscoresToCamelCaseImpl(String input, boolean capNextLetter)
  4. underscoresToSpaces(String value)