The apache libraries contain some methods to handle this as mentioned by B'bek Shakya and a comment, but if you are looking for a straight native Java solution you would do this as Bald Banta mentioned in the comments.
Here is a code example using streams:
public static void main(String[] args) {
String input = "fOo bar";
String transformed = Arrays.stream(input.toLowerCase()
.split(" "))
.map(String::toCharArray)
.map(arr -> {
arr[0] = Character.toUpperCase(arr[0]);
return arr;
})
.map(String::valueOf)
.collect(Collectors.joining(" "));
System.out.println(transformed);
}
And the same thing using a more common loop idiom:
public static void main(String[] args) {
String input = "fOo bar";
String[] words = input.toLowerCase().split(" ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < words.length; i++) {
char[] word = words[i].toCharArray();
word[0] = Character.toUpperCase(word[0]);
if (i != 0) {
sb.append(" ");
}
sb.append(String.valueOf(word));
}
System.out.println(sb.toString());
}