Convert the first letter of each word to uppercase

Does anyone know if there is another method than WordUtils.capitalize() that converts the first letter of each word to uppercase?

+6
source share
2 answers

You can use the created method:

 String CapsFirst(String str) { String[] words = str.split(" "); StringBuilder ret = new StringBuilder(); for(int i = 0; i < words.length; i++) { ret.append(Character.toUpperCase(words[i].charAt(0))); ret.append(words[i].substring(1)); if(i < words.length - 1) { ret.append(' '); } } return ret.toString(); } 
+7
source
 public static String caseFirst(String givenString) { String[] a= givenString.split(" "); StringBuffer s= new StringBuffer(); for (int i = 0; i < a.length; i++) { s.append(Character.toUpperCase(a[i].charAt(0))).append(a[i].substring(1)).append(" "); } return s.toString().trim(); } 
0
source

All Articles