Java Character isUpperCase() Example


Java Character API comes with many methods to check the case of a letter – lowercase or uppercase. After checking, the character can be converted from lowercase to uppercase or uppercase to lowercase as per the need of the logic.

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

  • public static boolean isUpperCase(char ch): Tests if the specified character ch is an uppercase character and the result of validation is returned as a boolean value.
Following Java Character isUpperCase() Example illustrates.
public class CharacterFunctionDemo
{
  public static void main(String args[])
  {
 
    char ch1 = 'A';
    char ch2 = 'a';

    boolean b1 = Character.isUpperCase(ch1);
    boolean b2 = Character.isUpperCase(ch2);

    System.out.println(ch1 + " character is uppercase letter: " + b1);     
    System.out.println(ch2 + " character is uppercase letter: " + b2);   

        // the isUpperCase() method can be used in control structures like this
    if(Character.isUpperCase('B') ==  Character.isUpperCase('K'))
    {
      System.out.println("\nBoth B and K are uppercase letters");
    }
        // after checking, change the case
    if(! Character.isUpperCase('b'))
    {
      System.out.println("\nb is converted to uppercase letter: " + Character.toUpperCase('b'));
    }
  }
}

Java Character isUpperCase() Example

Character.toUpperCase('b')

The static method toUpperCase(char ch) converts lowercase letter to uppercase letter. Check for isLowerCase().

Leave a Comment

Your email address will not be published.