Java Character toUpperCase() Method
Example
Make the first letter of a name uppercase:
public class Main {
public static void main(String[] args) {
String name = "john";
char first = Character.toUpperCase(name.charAt(0));
System.out.println(first + name.substring(1));
}
}
Definition and Usage
The toUpperCase() method returns the uppercase version of a character.
If the character is already uppercase, or is not a letter (like a digit), the method returns the same character.
Tip: Use the String toUpperCase() method to convert a whole string to uppercase.
Syntax
One of the following:
public static char toUpperCase(char ch)
public static int toUpperCase(int codePoint)
Most programs use the first version, with a char. The second version takes the character as a code point (the number that Unicode gives each character), as an int.
Parameter Values
| Parameter | Description |
|---|---|
| ch | Required. The character to convert. |
| codePoint | Required. The code point of the character to convert. |
Technical Details
| Returns: | The uppercase character. The first version returns a char, the second version returns a code point as an int. |
|---|
Related Pages
❮ Character Methods