Here you can find the source of toCamelCase(String name)
Parameter | Description |
---|---|
name | The string to convert to camel case. |
public static String toCamelCase(String name)
//package com.java2s; /*/*from ww w.jav a 2 s . c o m*/ * Copyright The Sett Ltd, 2005 to 2014. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Converts a string to camel case. * * @param name The string to convert to camel case. * * @return The string in camel case. */ public static String toCamelCase(String name) { String[] parts = name.split("_"); String result = parts[0]; for (int i = 1; i < parts.length; i++) { if (parts[i].length() > 0) { result += upperFirstChar(parts[i]); } } return result; } /** * Converts the first character of a string to upper case. * * @param name The string to convert the first character of. * * @return The string with its first character in upper case. */ public static String upperFirstChar(String name) { return name.substring(0, 1).toUpperCase() + name.substring(1); } }