Java String Camel Case To camelcaseToUppercase(String camelCase)

Here you can find the source of camelcaseToUppercase(String camelCase)

Description

Converts a name that's given in camel-case into upper-case, inserting underscores before upper-case letters.

License

Apache License

Parameter

Parameter Description
camelCase Name in camel-case notation.

Return

Name in upper-case notation.

Declaration

public static String camelcaseToUppercase(String camelCase) 

Method Source Code

//package com.java2s;
/**//www  .j  ava2 s  .  co  m
 * Copyright 2011 The Open Source Research Group,
 *                University of Erlangen-N?rnberg
 *
 * 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 name that's given in camel-case into upper-case, inserting
     * underscores before upper-case letters.
     * 
     * @param camelCase
     *            Name in camel-case notation.
     * @return Name in upper-case notation.
     */
    public static String camelcaseToUppercase(String camelCase) {
        int n = camelCase.length();
        StringBuilder upperCase = new StringBuilder(n * 4 / 3);
        for (int i = 0; i < n; ++i) {
            char ch = camelCase.charAt(i);
            if (Character.isUpperCase(ch)) {
                upperCase.append('_');
                upperCase.append(ch);
            } else {
                upperCase.append(Character.toUpperCase(ch));
            }
        }

        return upperCase.toString();
    }
}

Related

  1. camelCaseToPhrase(String camelCase)
  2. camelCaseToPretty(String camelCase)
  3. camelCaseToSeparatedWords(String ccString, String separator)
  4. camelCaseToSeparatorCase(String s, String separator)
  5. camelCaseToSpacedString(String camel)
  6. camelCaseToWords(String data)
  7. camelCaseUnderscores(String str)
  8. camelHump(String str)
  9. camelHumpsToWords(String camelHumps)