Java String Camel Case Format toCamelCase(String string)

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

Description

Converts a string to camel case, separated by spaces

License

Open Source License

Parameter

Parameter Description
string The String which is to be converted

Return

A camel cased string, transformed from s

Declaration

public static String toCamelCase(String string) 

Method Source Code

//package com.java2s;
/**/*from   www.j  a va2 s  .co m*/
 * Distributed as part of Fwap'a Derp UHC. A UHC plugin for Spigot 1.9
 * made by Ashrynn Macke (Flutterflies). You should have received a copy
 * of the MIT license with this code, if not please find it here:
 * https://opensource.org/licenses/MIT
 */

public class Main {
    /**
     * Converts a string to camel case, separated by spaces
     *
     * @param string The String which is to be converted
     * @return A camel cased string, transformed from s
     */
    public static String toCamelCase(String string) {
        String result = "";

        if (string.length() == 0) {
            return "";
        } else {
            for (String part : string.split(" ")) {
                result += Character.toUpperCase(part.charAt(0));
                if (string.length() > 1) {
                    result += part.substring(1, part.length()).toLowerCase();
                }
            }
        }

        return result;
    }
}

Related

  1. toCamelCase(String str)
  2. toCamelCase(String str)
  3. toCamelCase(String str, boolean firstCapital)
  4. toCamelCase(String string)
  5. toCamelCase(String string)
  6. toCamelCase(String string)
  7. toCamelCase(String string)
  8. toCamelCase(String string)
  9. toCamelCase(String stringValue, String delimiter)