Here you can find the source of camelCaseToEnum(String camelCase)
Parameter | Description |
---|---|
camelCase | a camelCase string |
public static String camelCaseToEnum(String camelCase)
//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(); } }