Here you can find the source of camelCaseToUnderScoreUpperCase(String camelCase)
Parameter | Description |
---|---|
camelCase | a camel case string : only letters without consecutive uppercase letters. |
public static String camelCaseToUnderScoreUpperCase(String camelCase)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w . j a v a 2 s . co m*/ * Convert a camel case string to underscored capitalized string. * eg. thisIsStandardCamelCaseString is converted to THIS_IS_STANDARD_CAMEL_CASE_STRING * @param camelCase a camel case string : only letters without consecutive uppercase letters. * @return the transformed string or the same if not camel case. */ public static String camelCaseToUnderScoreUpperCase(String camelCase) { String result = ""; boolean prevUpperCase = false; for (int i = 0; i < camelCase.length(); i++) { char c = camelCase.charAt(i); if (!Character.isLetter(c)) return camelCase; if (Character.isUpperCase(c)) { if (prevUpperCase) return camelCase; result += "_" + c; prevUpperCase = true; } else { result += Character.toUpperCase(c); prevUpperCase = false; } } return result; } }