public static String capitalize ( String s ) { StringBuilder result = new StringBuilder ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( i == 0 || i > 0 && ! Character . isLetterOrDigit ( s . charAt ( i - 1 ) ) ) c = Character . toUpperCase ( c ) ; else c = Character . toLowerCase ( c ) ; result . append ( c ) ; } return ( result . toString ( ) ) ; }
Capitalizes words and lowercases the rest