Java String Camel Case Format toCamelCase(String name)

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

Description

Method to convert case of string into camel case.

License

Apache License

Parameter

Parameter Description
name the name

Return

the string

Declaration

private static String toCamelCase(String name) 

Method Source Code

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

public class Main {
    /**//from   w  ww. j ava 2s. c o m
     * Method to convert case of string into camel case.
     * 
     * @param name
     *            the name
     * @return the string
     */
    private static String toCamelCase(String name) {
        name = name.toLowerCase();
        String[] parts = name.split(" ");
        String camelCaseString = parts[0].substring(0, 1).toLowerCase() + parts[0].substring(1);
        for (int i = 1; i < parts.length; i++) {
            camelCaseString = camelCaseString + toProperCase(parts[i]);
        }
        return camelCaseString;
    }

    /**
     * To proper case.
     * @param s
     *            the s
     * @return the string
     */
    private static String toProperCase(String s) {
        return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
    }
}

Related

  1. toCamelCase(String inputString)
  2. toCamelCase(String name)
  3. toCamelCase(String name)
  4. toCamelCase(String name)
  5. toCamelCase(String name)
  6. toCamelCase(String name)
  7. toCamelCase(String name)
  8. toCamelCase(String name)
  9. toCamelCase(String name)