Java String Camel Case To camelCaseToEnum(String camelCase)

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

Description

Converts camelCaseStringsWithACRONYMS to CAMEL_CASE_STRINGS_WITH_ACRONYMS

License

Apache License

Parameter

Parameter Description
camelCase a camelCase string

Return

the same string in equivalent format for Java enum values

Declaration

public static String camelCaseToEnum(String camelCase) 

Method Source Code

//package com.java2s;
/*//from   www . java  2s  .  co m
 * Copyright 2010-2013 the original author or authors.
 * 
 * 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 camelCaseStringsWithACRONYMS to CAMEL_CASE_STRINGS_WITH_ACRONYMS
     * 
     * @param camelCase a camelCase string
     * @return the same string in equivalent format for Java enum values
     */
    public static String camelCaseToEnum(String camelCase) {
        final String regex = "([a-z])([A-Z])";
        final String replacement = "$1_$2";

        return camelCase.replaceAll(regex, replacement).toUpperCase();
    }
}

Related

  1. camelCaseToDash(String input)
  2. camelCaseToDashes(String camelCaseString, int startIndex, String prefix)
  3. camelCaseToDashLowerName(String name)
  4. camelCaseToDashSeperated(String s)
  5. camelCaseToDotNotation(String string)
  6. camelCaseToEnum(String name)
  7. camelCaseToHuman(String input)
  8. camelCaseToPhrase(String camelCase)
  9. camelCaseToPretty(String camelCase)