Java String Camel Case camelize(String value)

Here you can find the source of camelize(String value)

Description

camelize

License

Apache License

Declaration

public static String camelize(String value) 

Method Source Code

//package com.java2s;
/**//  w  w w. ja v  a  2s.c om
 * Copyright 2008-2015 Qualogy Solutions B.V.
 *
 * 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 {
    public static String camelize(String value) {
        if ((value == null) || (value.length() == 0)) {
            return value;
        }
        if (value.indexOf("-") == -1) {
            return value;
        }
        String[] tokens = value.split("-");
        StringBuffer newValue = new StringBuffer(tokens[0].toLowerCase());
        for (int i = 1; i < tokens.length; i++) {
            String token = tokens[i];
            newValue.append(token.substring(0, 1).toUpperCase());
            newValue.append(token.substring(1));
        }
        return newValue.toString();
    }

    public static String toString(Object value, String defaultValue) {
        if (value instanceof String) {
            return (String) value;
        }
        if (value != null) {
            return value.toString();
        }
        return defaultValue;
    }
}

Related

  1. cameliza(String str)
  2. cameliza(String str)
  3. camelize(String s)
  4. camelize(String underScore)
  5. camelize(String value)