Java String Camel Case to Upper Case camelCaseToUpperCase(final String camelCase)

Here you can find the source of camelCaseToUpperCase(final String camelCase)

Description

camel Case To Upper Case

License

Apache License

Declaration

public static String camelCaseToUpperCase(final String camelCase) 

Method Source Code

//package com.java2s;
/*/*from w  w w  .ja  va2s  .  com*/
 * $Id: StringUtil.java,v 1.2 2009-06-30 14:14:38 concentus Exp $
 * 
 * Copyright 2005 Sebastian Hasait
 * 
 * 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 camelCaseToUpperCase(final String camelCase) {
        StringBuffer result = new StringBuffer();
        boolean lastWasNotUpperCase = false;
        for (int chI = 0; chI < camelCase.length(); chI++) {
            char ch = camelCase.charAt(chI);
            if (Character.isUpperCase(ch)) {
                if (lastWasNotUpperCase) {
                    result.append("_");
                }
                lastWasNotUpperCase = false;
            } else {
                lastWasNotUpperCase = true;
            }
            result.append(Character.toUpperCase(ch));
        }
        return result.toString();
    }

    public static String toString(final Object object, final String nullString) {
        if (object == null) {
            return nullString;
        }
        return object.toString();
    }

    public static String toString(final Object object) {
        return toString(object, null);
    }
}

Related

  1. camelCaseToUpperCase(String camelCaseName)
  2. camelCaseToUpperCase(String in)
  3. camelToUpper(String camel)
  4. camelToUpper(String name)