Java String Camel Case Format toCamelCase(String s)

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

Description

to Camel Case

License

Apache License

Declaration

public static String toCamelCase(String s) 

Method Source Code

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

public class Main {
    public static String toCamelCase(String s) {

        String[] parts = s.split("_");

        //All caps without '_'
        if (parts.length == 0) {
            return s.toLowerCase();
        }/*from  ww w . j av a 2  s . c o m*/

        String camelCaseString = "";
        for (int i = 0; i < parts.length; i++) {

            if (i == 0) {
                camelCaseString = parts[i].toLowerCase();
            } else {
                camelCaseString = camelCaseString + toProperCase(parts[i]);
            }
        }
        return camelCaseString;
    }

    public static String toProperCase(String s) {
        return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
    }
}

Related

  1. toCamelCase(String s)
  2. toCamelCase(String s)
  3. toCamelCase(String s)
  4. toCamelCase(String s)
  5. toCamelCase(String s)
  6. toCamelCase(String s, boolean firstCharUppercase)
  7. toCamelCase(String s, Boolean firstUpper)
  8. toCamelCase(String s, String separator, boolean capitalizeFirstPart)
  9. toCamelCase(String start)