question: public static String asJavaIdentifier ( String s ) { if ( s . isEmpty ( ) ) return "$0" ; StringBuilder b = new StringBuilder ( ) ; if ( ! s . startsWith ( "$" ) ) { b . append ( "$" ) ; for ( char c : s . toCharArray ( ) ) if ( Character . isJavaIdentifierPart ( c ) ) b . append ( c ) ; else b . append ( "_" ) ; } else { b . append ( s ) ; } return b . toString ( ) ; }
target:  Converts Strings to valid java Identifiers by replacing illegal characters with underscores.