Java - Write code to convert spaced separated string to Title Case

Requirements

Write code to convert spaced separated string to Title Case

Demo

import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import Armadillo.Core.Logger;

public class Main{
    public static void main(String[] argv){
        String input = "abc def";
        System.out.println(toTitleCase(input));
    }/*  ww  w.j  a v  a 2 s .  c om*/
    public static String toTitleCase(String input) {
        StringBuilder titleCase = new StringBuilder();
        boolean nextTitleCase = true;

        for (char c : input.toCharArray()) {
            if (Character.isSpaceChar(c)) {
                nextTitleCase = true;
            } else if (nextTitleCase) {
                c = Character.toTitleCase(c);
                nextTitleCase = false;
            }

            titleCase.append(c);
        }

        return titleCase.toString();
    }
}