Java String Camel Case Format toCamelCase(String string)

Here you can find the source of toCamelCase(String string)

Description

Converts the string to camelcase.

License

Open Source License

Parameter

Parameter Description
string the string to be camelcased.

Return

the camel cased string.

Declaration

public static String toCamelCase(String string) 

Method Source Code

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

public class Main {
    /**/* w ww . j a  v  a 2  s .  co m*/
     * Converts the string to camelcase. Strings are of the format: THIS_IS_A_STRING, and the result of camel casing
     * would be thisIsAString.
     * 
     * @param string the string to be camelcased.
     * @return the camel cased string.
     * @since 2.0
     */
    public static String toCamelCase(String string) {
        StringBuffer result = new StringBuffer(string);
        while (result.indexOf("_") != -1) { //$NON-NLS-1$
            int indexOf = result.indexOf("_"); //$NON-NLS-1$
            result.replace(indexOf, indexOf + 2, "" + Character.toUpperCase(result.charAt(indexOf + 1))); //$NON-NLS-1$
        }
        return result.toString();
    }
}

Related

  1. toCamelCase(String str)
  2. toCamelCase(String str)
  3. toCamelCase(String str)
  4. toCamelCase(String str)
  5. toCamelCase(String str, boolean firstCapital)
  6. toCamelCase(String string)
  7. toCamelCase(String string)
  8. toCamelCase(String string)
  9. toCamelCase(String string)