Java String Camel Case Format toCamelCase(String dashCase)

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

Description

to Camel Case

License

Open Source License

Declaration

public static String toCamelCase(String dashCase) 

Method Source Code

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

public class Main {
    public static String toCamelCase(String dashCase) {
        // Split on dash and space
        String[] parts = dashCase.toLowerCase().split("[- ]+");
        StringBuilder builder = new StringBuilder();

        // Make the first character upper case
        for (String part : parts) {
            if (part.length() > 0) {
                builder.append(part.substring(0, 1).toUpperCase());
                builder.append(part.substring(1));
            }/*  w ww . j  av  a 2  s.  co  m*/
        }

        // First char is lower case
        if (builder.length() > 0) {
            String firstChar = builder.substring(0, 1).toLowerCase();
            builder.replace(0, 1, firstChar);
        }

        return builder.toString();
    }
}

Related

  1. toCamelCase(final String string)
  2. toCamelCase(String anyCase, char wordMarker)
  3. toCamelCase(String argString)
  4. toCamelCase(String begin, String... parts)
  5. toCamelCase(String columnName)
  6. toCamelCase(String id)
  7. toCamelCase(String in, boolean startWithUpper)
  8. toCamelCase(String input)
  9. toCamelCase(String input)