Java String Capitalize capitalize(String string)

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

Description

Returns the specified string with its first character converted to upper case.

License

Open Source License

Parameter

Parameter Description
string the String to be processed

Return

the specified string with its first character converted to upper case

Declaration

public static String capitalize(String string) 

Method Source Code

//package com.java2s;

public class Main {
    /**//www. j  av  a 2s.c om
     * Returns the specified string with its first character converted to
     * upper case.
     * 
     * @param string the String to be processed
     * @return the specified string with its first character converted to
     * upper case
     */
    public static String capitalize(String string) {
        int length = string.length();
        if (length == 0) {
            return string;
        } else if (length == 1) {
            return string.toUpperCase();
        } else {
            return (Character.toUpperCase(string.charAt(0)) + string.substring(1));
        }
    }
}

Related

  1. capitalize(String string)
  2. capitalize(String string)
  3. capitalize(String string)
  4. capitalize(String string)
  5. capitalize(String string)
  6. capitalize(String string)
  7. capitalize(String string)
  8. capitalize(String string)
  9. capitalize(String string)