Java String Capitalize capitalizeName(String name)

Here you can find the source of capitalizeName(String name)

Description

Capitalizes the first word of the supplied name, preserves the case of subsequent words and lower cases all other letters.

License

Open Source License

Declaration

public static String capitalizeName(String name) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   w  w w.  j  a  v a2 s .c om
     * Capitalizes the first word of the supplied name, preserves the case of
     * subsequent words and lower cases all other letters.
     */
    public static String capitalizeName(String name) {
        StringBuilder cname = new StringBuilder();
        boolean wasSpace = false;
        for (int ii = 0, ll = name.length(); ii < ll; ii++) {
            char c = name.charAt(ii);
            if (ii == 0) {
                cname.append(Character.toUpperCase(c));
            } else if (wasSpace) {
                cname.append(c);
            } else {
                cname.append(Character.toLowerCase(c));
            }
            wasSpace = Character.isWhitespace(c);
        }
        return cname.toString();
    }
}

Related

  1. capitalizeHeadingCharacter(final String value)
  2. capitalizeInitial(String str)
  3. capitalizeMessage(String message)
  4. capitalizeMethodName(String methodName)
  5. capitalizeName(final String name)
  6. capitalizePackageName(final String packageName)
  7. capitalizePlayerName(String name)
  8. capitalizePropertyName(String propertyName)
  9. capitalizePropertyName(String s)