5 Ways: Java Program to Capitalize the first character of each word in a string
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO5n2b8srtnYGuY2AdAd2G4KNN3CW-pYgqWl_xikULjYY-MvXutqcS1BCwjnFLJXL4VVJiQ1eeJoWb2_XT5tmoSs2oYTRrGZ-RRVDwgyNXHmtnMSYJtgZhFqNf35N5ClqqKuu70WpvOqTMrrnQvmKRvDqtJorSOAHQCfxjJOKvsWASGnPl5w0Vfy1aVlKA/w400-h216/capitalize-first-character-of-each-word-java.png)
In this section, we will show five different ways to capitalize the first letter of each word in a string in Java. 1. Using For loop and toUpperCase() method 2. Using Java 8 Streams 3. Using regex and replaceAll() method 4. Using Apache Commons Text 5. Using Google Guava 1. Using For loop and toUpperCase() method public class Main { public static void main ( String [] args) { String string = "java is awesome" ; String [] arr = string .split( " " ); StringBuilder stringBuilder = new StringBuilder (); for ( int i = 0 ; i < arr . length ; i ++) { stringBuilder .append( Character . toUpperCase ( arr [ i ].charAt( 0 ))) .append( arr [ i ].substring( 1 )).append( " " ); } String result = stringBuilder .toString(); System . out .println( result ); } } Here we are using split() split the string based on whitespace. It returns an Array of String. Iterate