Java String Capitalize First capitalizeFirstCharacter(String str)

Here you can find the source of capitalizeFirstCharacter(String str)

Description

Returns the given String in lower case with the first character capitalized.

License

Open Source License

Parameter

Parameter Description
str The String to convert to lower case then capitalized the first character.

Return

The given String in lower case with the first character capitalized.

Declaration

public static String capitalizeFirstCharacter(String str) 

Method Source Code

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

public class Main {
    /**//from  w w w.  java 2 s  .  c  om
     *  Returns the given String in lower case with the first character capitalized.
     * 
     * @param str The String to convert to lower case then capitalized the first character.
     * 
     * @return The given String in lower case with the first character capitalized.
     */
    public static String capitalizeFirstCharacter(String str) {
        if (str == null)
            throw new IllegalArgumentException("Parameter 'str' cannot be null!");

        if (str.length() <= 0)
            return "";

        str = str.toLowerCase();

        StringBuilder sb = new StringBuilder();

        sb.append(Character.toUpperCase(str.charAt(0)));

        sb.append(str.substring(1));

        return sb.toString();
    }
}

Related

  1. capitalizeFirstChar(String s)
  2. capitalizeFirstCharacter(final String s)
  3. capitalizeFirstCharacter(String s)
  4. capitalizeFirstCharacter(String s)
  5. capitalizeFirstCharacter(String str)
  6. CapitalizeFirstCharacter(String Str)
  7. capitalizeFirstCharacter(String value)
  8. capitalizeFirstCharacters(String whole)
  9. capitalizeFirstCharacterString(String item)