Java Character toUpperCase() Example

Java Character API comes with many methods to convert a character’s type to another type. toUpperCase(char ch) converts lowercase ch letter to uppercase. After conversion, you can check the character is really converted or not with isUpperCase() method. If the character is already an uppercase one, it is returned as it is by the method.

Following is the method signature as defined in java.lang.Character class.

  • public static char toUpperCase(char ch): Converts the character ch from lowercase to uppercase.

Following example illustrates. Just for logic point of view, a digit is also taken to see how toUpperCase() method acts.

public class CharacterFunctionDemo
  public static void main(String args[])
   char ch1 = 'a';
   char ch2 = '5';                            // observe, it is digit

   char ch3 = Character.toUpperCase(ch1);
   char ch4 = Character.toUpperCase(ch2);

   System.out.println(ch1 + " is converted to " + ch3);     
   System.out.println(ch2 + " digit is converted to " + ch4);   

   System.out.println("\nch3 is uppercase letter: " + Character.isUpperCase(ch3));
   System.out.println("ch4 is uppercase letter: " + Character.isUpperCase(ch4));

Java Character toUpperCase() Example

Character.isUpperCase(char ch)

Checks the character is uppercase of not. If upprcase, the method returns true else false. Know the usage of toLowerCase().

Leave a Comment

Your email address will not be published.