As mentioned in the comments, there are many answers to this question. Just for fun I wrote my own method real quick. Feel free to use it and/or improve it:
java
public static String capitalizeAllWords(String str) {
String phrase = "";
boolean capitalize = true;
for (char c : str.toLowerCase().toCharArray()) {
if (Character.isLetter(c) && capitalize) {
phrase += Character.toUpperCase(c);
capitalize = false;
continue;
} else if (c == ' ') {
capitalize = true;
}
phrase += c;
}
return phrase;
}
Test:
java
String str = "this is a test message";
System.out.print(capitalizeAllWords(str));
Output:
java
This Is A Test Message