public static String toTitleCase ( String text ) { StringBuilder str = new StringBuilder ( ) ; String [ ] words = text . trim ( ) . split ( "\\s" ) ; for ( int i = 0 ; i < words . length ; i ++ ) { if ( words [ i ] . length ( ) > 0 ) { if ( i > 0 ) { str . append ( " " ) ; } String lower = words [ i ] . toLowerCase ( Locale . getDefault ( ) ) ; if ( words [ i ] . length ( ) == 1 ) { str . append ( lower ) ; } else if ( words [ i ] . length ( ) == 2 ) { if ( lower . equals ( "da" ) || lower . equals ( "de" ) || lower . equals ( "do" ) || lower . equals ( "di" ) ) str . append ( lower ) ; else str . append ( StringUtils . capitalize ( lower ) ) ; } else { str . append ( StringUtils . capitalize ( lower ) ) ; } } } return str . toString ( ) ; }
Converte string para title case .