Java String Camel Case Format toCamelCase(String value)

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

Description

Remove spaces, make each word start with uppercase.

License

Open Source License

Declaration

public static String toCamelCase(String value) 

Method Source Code

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

public class Main {
    /**/*from  w ww  .j  a v a 2  s . co m*/
     * Remove spaces, make each word start with uppercase.
     * CamelCase is a method for removing spaces from a phrase while maintaining leglibility.
     *  
     * For example "Small molecule" -> "SmallMolecule"
     * "Show me your ID!" -> "ShowMeYourID!"
     * "Two  spaces" -> "TwoSpaces"
     * " surrounded " -> "Surrounded"
     * Null-Safe: returns null if input is null;
     */
    public static String toCamelCase(String value) {
        if (value == null)
            return null;

        StringBuilder result = new StringBuilder();
        for (String word : value.trim().split(" +")) {
            result.append(word.substring(0, 1).toUpperCase());
            result.append(word.substring(1));
        }
        return result.toString();
    }

    /**
     * Null-Safe version of String.toLowerCase;
     */
    public static String toUpperCase(String input) {
        if (input == null)
            return null;
        return input.toUpperCase();
    }
}

Related

  1. toCamelCase(String text, boolean capFirstLetter)
  2. toCamelCase(String value)
  3. toCamelCase(String value)
  4. toCamelCase(String value)
  5. toCamelCase(String value)
  6. toCamelCase(String value, String separator)
  7. toCamelCaseCapitalize(String underLineName)
  8. toCamelCaseIdentifier(String formStr)
  9. toCamelCaseIgnoringLastChar(String string, String delimiter, boolean upperFirst)