Check whether a character is Uppercase or not in Java

Java 8Object Oriented ProgrammingProgramming

To check whether a character is in Uppercase or not in Java, use the Character.isUpperCase() method.

We have a character to be checked.

char val = 'K';

Now let us use the Character.isUpperCase() method.

if (Character.isUpperCase(val)) {
   System.out.println("Character is in Uppercase!");
}else {
   System.out.println("Character is in Lowercase!");
}

Let us see the complete example now to check for Uppercase in Java.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      System.out.println("Checking for Uppercase character...");
      char val = 'K';
      System.out.println("Character: "+val);
      if (Character.isUpperCase(val)) {
         System.out.println("Character is in Uppercase!");
      }else {
         System.out.println("Character is in Lowercase!");
      }
   }
}

Output

Checking for Uppercase character...
Character: K
Character is in Uppercase!
raja
Published on 13-Nov-2018 14:31:03
Advertisements