Java String Camel Case camelCase(String in)

Here you can find the source of camelCase(String in)

Description

Camel case anY STRING given as InPuT.
returns :
CamelCaseAnyStringGivenAsInput.

License

Open Source License

Declaration

public static String camelCase(String in) 

Method Source Code

//package com.java2s;
//    it under the terms of the GNU General Public License as published by

public class Main {
    /**//from w w  w . ja v a2s  . c om
     * Camel case anY STRING given as InPuT.<br>
     * returns : <br>
     * CamelCaseAnyStringGivenAsInput.
     */
    public static String camelCase(String in) {
        return removeWhiteSpaces(capitalize(in.toLowerCase(), true));
    }

    public static String removeWhiteSpaces(String in) {
        return in.replaceAll("\\s+", "");
    }

    /**
     * Capitalize the first letter of a text. Example : capitalize("toto")
     * returns "Toto"
     */
    public static String capitalize(String in) {
        return capitalize(in, false);
    }

    /**
     * Capitalize all words in a text. Result is trimmed, and all sequences of
     * white characters are replaced by a regular space: " ".
     * 
     * @param in
     * @param all
     * @return "toto tata" gives "Toto Tata"
     */
    public static String capitalize(String in, boolean all) {
        if (in == null || in.equals(""))
            return in;
        if (!all)
            return in.substring(0, 1).toUpperCase() + in.substring(1);
        else {
            StringBuffer out = new StringBuffer("");
            for (String word : in.split("\\s+")) {
                out.append(" ").append(capitalize(word));
            }
            return out.toString().trim();
        }
    }
}

Related

  1. camelCase(final String prefix, final String str)
  2. camelCase(final String text)
  3. camelCase(final String value, final String delim)
  4. camelCase(String column)
  5. camelCase(String content)
  6. camelCase(String in)
  7. camelCase(String input)
  8. camelCase(String inStr, int start, int end)
  9. camelCase(String key)