public static String camelCaseToSnakeCase ( String camelCase ) { if ( null == camelCase || camelCase . length ( ) == 0 ) return camelCase ; StringBuilder snakeCase = new StringBuilder ( camelCase . length ( ) + 3 ) ; snakeCase . append ( camelCase . charAt ( 0 ) ) ; boolean hasCamelCase = false ; for ( int i = 1 ; i < camelCase . length ( ) ; i ++ ) { char c = camelCase . charAt ( i ) ; if ( Character . isUpperCase ( c ) ) { snakeCase . append ( "-" ) ; c = Character . toLowerCase ( c ) ; hasCamelCase = true ; } snakeCase . append ( c ) ; } if ( ! hasCamelCase ) return camelCase ; return snakeCase . toString ( ) ; }
Transform a snake - case string to a camelCase one .