Java String Capitalize First capitalizeFirstLetter(String string)

Here you can find the source of capitalizeFirstLetter(String string)

Description

This method capitalizes the first character of the string.

License

Open Source License

Parameter

Parameter Description
string The string to be capitalized.

Return

The new capitalized string.

Declaration

public static String capitalizeFirstLetter(String string) 

Method Source Code

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

public class Main {
    /**//from   w  w  w .  ja v a 2 s.  c o  m
     * This method capitalizes the first character of the string.
     * @param string The string to be capitalized.
     * @return The new capitalized string.
     */
    public static String capitalizeFirstLetter(String string) {
        /**
         * If the string isempty or null,
         * return the string itself.
         */
        if (string.trim().isEmpty() || (string == null)) {
            return string;
        } else {
            /**
             * If not, then capitalize the first character and return the String.
             */
            return Character.toUpperCase(string.charAt(0)) + string.substring(1);
        }

    }
}

Related

  1. capitalizeFirstLetter(String str)
  2. capitalizeFirstLetter(String str)
  3. capitalizeFirstLetter(String str)
  4. capitalizeFirstLetter(String str)
  5. capitalizeFirstLetter(String string)
  6. capitalizeFirstLetter(String text)
  7. capitalizeFirstLetter(String[] strArr)
  8. capitalizeFirstOnly(String original)
  9. capitalizeFirstOnly(String s)