Here you can find the source of toCamelCase(String text)
Parameter | Description |
---|---|
text | The text to camel case |
public static String toCamelCase(String text)
//package com.java2s; /**//ww w .j ava 2s . c o m * Copyright (C) 2014-2015 LinkedIn Corp. (pinot-core@linkedin.com) * * 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 { /** * Takes a string, removes all characters that are not letters or digits and capitalizes the next letter following a * series of characters that are not letters or digits. For example, toCamelCase("Hello world!") returns "HelloWorld". * * @param text The text to camel case * @return The camel cased version of the string given */ public static String toCamelCase(String text) { int length = text.length(); StringBuilder builder = new StringBuilder(length); boolean capitalizeNextChar = false; for (int i = 0; i < length; i++) { char theChar = text.charAt(i); if (Character.isLetterOrDigit(theChar) || theChar == '.') { if (capitalizeNextChar) { builder.append(Character.toUpperCase(theChar)); capitalizeNextChar = false; } else { builder.append(theChar); } } else { capitalizeNextChar = true; } } return builder.toString(); } }