Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting first letter of each word to uppercase [closed]

Tags:

java

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

like image 902
javaGeek Avatar asked Mar 21 '14 01:03

javaGeek


1 Answers

You could use a method you create:

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();
}
like image 178
PlasmaPower Avatar answered Oct 03 '22 12:10

PlasmaPower