The toUpperCase()
method is a static method in the Character
class in Java that converts a character to uppercase.
The input for this function is a character.
Note: If you need to convert a string to uppercase, refer to the String.toUpperCase method.
public static char toUpperCase(char ch)
char ch
- the character to convert to uppercaseThis method returns the uppercase version of the input character.
toUpperCase()
converts a lowercase character to uppercase.
toUpperCase()
converts a uppercase character to uppercase.
In the code below, we use the toUpperCase
function to convert non-alphabetic character to uppercase.
public class Main {public static void main( String args[] ) {char ch = 'a';System.out.println(Character.toUpperCase(ch));ch = 'A';System.out.println(Character.toUpperCase(ch));ch = 'z';System.out.println(Character.toUpperCase(ch));ch = 'Z';System.out.println(Character.toUpperCase(ch));}}
We take theexample of ?
. Since it is not an alphabetic character, it remains unchanged.
In the code below, we use the toUpperCase
function to convert non-alphabetic character to uppercase.
public class Main {public static void main( String args[] ) {char nonAlphabeticChar = '?';// Since '?' is not an alphabetic character, it remains unchangedchar unchangedChar = Character.toUpperCase(nonAlphabeticChar);System.out.println("Uppercase of '" + nonAlphabeticChar + "' is: " + unchangedChar);}}