Java String Camel Case Format toCamelCase(String s, String separator, boolean capitalizeFirstPart)

Here you can find the source of toCamelCase(String s, String separator, boolean capitalizeFirstPart)

Description

Turns the string into CamelCase.

License

Apache License

Parameter

Parameter Description
s source string
separator the separator between string parts
capitalizeFirstPart true, if the first string part must be capitalized

Return

string in CamelCase.

Declaration

public static String toCamelCase(String s, String separator,
        boolean capitalizeFirstPart) 

Method Source Code

//package com.java2s;
/**/*from  ww w  . j  a  va 2s . c  o m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 {
    /**
     * Turns the string into CamelCase.
     * @param s source string
     * @param separator the separator between string parts
     * @param capitalizeFirstPart true, if the first string part must be capitalized
     * @return string in CamelCase.
     */
    public static String toCamelCase(String s, String separator,
            boolean capitalizeFirstPart) {
        String[] parts = s.split(separator);
        String result = capitalizeFirstPart ? toCapitalCase(parts[0])
                : parts[0];
        for (int i = 1; i < parts.length; i++) {
            result += toCapitalCase(parts[i]);
        }
        return result;
    }

    /**
     * Turns the first letter of the string into capital letter
     * @param s source string
     * @return capitalized string
     */
    public static String toCapitalCase(String s) {
        String ss = s;
        if (s != null && s.length() > 0) {
            ss = s.substring(0, 1).toUpperCase();
            if (s.length() > 1) {
                ss += s.substring(1);
            }
        }
        return ss;
    }
}

Related

  1. toCamelCase(String s)
  2. toCamelCase(String s)
  3. toCamelCase(String s)
  4. toCamelCase(String s, boolean firstCharUppercase)
  5. toCamelCase(String s, Boolean firstUpper)
  6. toCamelCase(String start)
  7. toCamelCase(String str)
  8. toCamelCase(String str)
  9. toCamelCase(String str)