Java String Camel Case Format toCamelCase(final String inputString, boolean avoidFirst)

Here you can find the source of toCamelCase(final String inputString, boolean avoidFirst)

Description

Replaces the white spaces and the "-" and transform the String in camel case

License

Open Source License

Parameter

Parameter Description
inputString The string to be transformed
avoidFirst Define true if you want to discard the first word

Return

The transformed string in camel case

Declaration

public static String toCamelCase(final String inputString, boolean avoidFirst) 

Method Source Code

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

public class Main {
    /**/*from  w w w.  j  a  va  2 s  . co  m*/
     * Replaces the white spaces and the "-" and transform the String in camel
     * case
     * 
     * @param inputString
     *            The string to be transformed
     * @param avoidFirst
     *            Define true if you want to discard the first word
     * @return The transformed string in camel case
     */
    public static String toCamelCase(final String inputString, boolean avoidFirst) {
        if (inputString == null)
            return null;

        final StringBuilder ret = new StringBuilder(inputString.length());

        for (final String word : inputString.replaceAll("_", " ").split("[ -]")) {
            if (avoidFirst) {
                ret.append(word.toLowerCase());
                avoidFirst = false;
                continue;
            }
            if (!word.isEmpty() && !avoidFirst) {
                ret.append(word.substring(0, 1).toUpperCase());
                ret.append(word.substring(1).toLowerCase());
            }
        }

        return ret.toString();
    }
}

Related

  1. toCamelCase(final String identifier, boolean capital)
  2. toCamelCase(final String init)
  3. toCamelCase(final String input, final char spacer)
  4. toCamelCase(final String string)
  5. toCamelcase(final String string)
  6. toCamelCase(final String string)
  7. toCamelCase(String anyCase, char wordMarker)