public static String capitalize(String text) {
    
        if (text == null) return null;
        
        if (text.length() == 1) return text.toUpperCase();

        String s = "";

        for (int i = 0; i < text.length(); i++)
            if (i - 1 < 0 || text.charAt(i - 1) == ' ')
                s += ("" + text.charAt(i)).toUpperCase();
            else
                s += ("" + text.charAt(i)).toLowerCase();
        
        return s;
    }