Java String Capitalize capitalize(String name)

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

Description

Thus "fooBah" becomes "FooBah" and "X" becomes "X".

License

Apache License

Parameter

Parameter Description
name The string to be capitalized.

Return

The capitalized version of the string.

Declaration


public static String capitalize(String name) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  ww .  j  a v a2  s .  c  o  m*/
     * Thus "fooBah" becomes "FooBah" and "X" becomes "X".
     * 
     * @param name
     *            The string to be capitalized.
     * @return The capitalized version of the string.
     */

    public static String capitalize(String name) {
        if (name.length() == 0) {
            return name;
        }
        if (Character.isUpperCase(name.charAt(0))) {
            return name;
        }
        char chars[] = name.toCharArray();
        char c = chars[0];
        char modifiedChar = Character.toUpperCase(c);
        if (modifiedChar == c) {
            return name;
        }
        chars[0] = modifiedChar;
        return new String(chars);
    }
}

Related

  1. capitalize(String input)
  2. capitalize(String inputString)
  3. capitalize(String line)
  4. capitalize(String membername)
  5. capitalize(String message)
  6. capitalize(String name)
  7. capitalize(String name)
  8. capitalize(String name)
  9. capitalize(String name)