public static String underscoresToCamelCase ( String input , boolean capitializeNextLetter ) { StringBuilder result = new StringBuilder ( ) ; for ( int i = 0 ; i < input . length ( ) ; i ++ ) { char ch = input . charAt ( i ) ; if ( ' ' <= ch && ch <= ' ' ) { if ( capitializeNextLetter ) { result . append ( ( char ) ( ch + ( ' ' - ' ' ) ) ) ; } else { result . append ( ch ) ; } capitializeNextLetter = false ; } else if ( ' ' <= ch && ch <= ' ' ) { if ( i == 0 && ! capitializeNextLetter ) { // Force first letter to lower-case unless explicitly told to // capitalize it. result . append ( ( char ) ( ch + ( ' ' - ' ' ) ) ) ; } else { // Capital letters after the first are left as-is. result . append ( ch ) ; } capitializeNextLetter = false ; } else if ( ' ' <= ch && ch <= ' ' ) { result . append ( ch ) ; capitializeNextLetter = true ; } else { capitializeNextLetter = true ; } } return result . toString ( ) ; }
Converts underscore field names to camel case while preserving camel case field names .