Java String Camel Case Format toCamelCase(String string)

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

Description

to Camel Case

License

Apache License

Declaration

public static String toCamelCase(String string) 

Method Source Code

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

public class Main {
    public static String toCamelCase(String string) {
        StringBuilder result = new StringBuilder();

        // [#2515] - Keep trailing underscores
        for (String word : string.split("_", -1)) {

            // Uppercase first letter of a word
            if (word.length() > 0) {

                // [#82] - If a word starts with a digit, prevail the
                // underscore to prevent naming clashes
                if (Character.isDigit(word.charAt(0))) {
                    result.append("_");
                }/* www.  j  a v a 2s.  c o m*/

                result.append(word.substring(0, 1).toUpperCase());
                result.append(word.substring(1).toLowerCase());
            } else {
                // If no letter exists, prevail the underscore (e.g. leading
                // underscores)
                result.append("_");
            }
        }

        return result.toString();
    }
}

Related

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