Java String Capitalize First capitalizeFirstLetter(String str)

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

Description

Makes the first letter uppercase of the given String.

License

Open Source License

Parameter

Parameter Description
str will be used in capitaling operation.

Return

capitalized state of the given param.

Declaration

public static String capitalizeFirstLetter(String str) 

Method Source Code

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

public class Main {
    /**//from   www  .jav  a  2s  .c  o m
     * Makes the first letter uppercase of the given String.
     *
     * @param str will be used in capitaling operation.
     * @return capitalized state of the given param.
     */
    public static String capitalizeFirstLetter(String str) {
        if (str == null || str.length() == 0) {
            return str;
        }
        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.append(Character.toTitleCase(str.charAt(0)));
        if (str.length() > 1) {
            stringBuilder.append(str.substring(1));
        }
        return stringBuilder.toString();
    }
}

Related

  1. capitalizeFirstLetter(String s)
  2. capitalizeFirstLetter(String str)
  3. capitalizeFirstLetter(String str)
  4. capitalizeFirstLetter(String str)
  5. capitalizeFirstLetter(String str)
  6. capitalizeFirstLetter(String str)
  7. capitalizeFirstLetter(String str)
  8. capitalizeFirstLetter(String string)
  9. capitalizeFirstLetter(String string)