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

Parameter

Parameter Description
s a parameter

Declaration

public static String toCamelCase(String s) 

Method Source Code

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

public class Main {
    public static final String DEFAULT_CAMEL_CASE_SPLIT = "_";

    /**// www  .j a  v  a  2s . c o  m
     * 
     * @param s
     * @return
     */
    public static String toCamelCase(String s) {
        return toCamelCase(s, DEFAULT_CAMEL_CASE_SPLIT, false);
    }

    /**
     * 
     * @param s
     * @param capitalizeFirst
     * @return
     */
    public static String toCamelCase(String s, boolean capitalizeFirst) {
        return toCamelCase(s, DEFAULT_CAMEL_CASE_SPLIT, capitalizeFirst);
    }

    /**
     * 
     * @param s
     * @param regex
     * @return
     */
    public static String toCamelCase(String s, String regex) {
        return toCamelCase(s, regex, false);
    }

    /**
     * 
     * @param s
     *          the String to format
     * @param regex
     *          the regex to split the String on for camel case
     * @param capitalizeFirst
     *          boolean if the first letter should be capitalized
     * @return a String in camel case
     */
    public static String toCamelCase(String s, String regex, boolean capitalizeFirst) {
        String[] split = s.split(regex);
        StringBuilder sb = new StringBuilder();
        for (String current : split) {
            String first = current.substring(0, 1);
            String last = current.substring(1).toLowerCase();
            sb.append(capitalizeFirst ? first.toUpperCase() : first.toLowerCase());
            sb.append(last);
            capitalizeFirst = true;
        }
        return sb.toString();
    }
}

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)
  7. toCamelCase(String s, boolean firstCharUppercase)
  8. toCamelCase(String s, Boolean firstUpper)
  9. toCamelCase(String s, String separator, boolean capitalizeFirstPart)