isLetterOrDigit() method in Java


The isLetterOrDigit() method in Java returns TRUE if the entered value is a letter or digit.

We have the following character.

char val ='P';

Now, let us check for letter or digit using if-else decision-making statement.

if (Character.isLetterOrDigit(val)) {
   System.out.println("Value is a letter or digit!");
} else {
   System.out.println("Value is neither a letter nor a digit!");
}

The following is an example.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      char val ='P';
      System.out.println("Value: "+val);
      if (Character.isLetterOrDigit(val)) {
         System.out.println("Value is a letter or digit!");
      } else {
         System.out.println("Value is neither a letter nor a digit!");
      }
   }
}

Output

Value: P
Value is a letter or digit!

Let us see another example.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      char val ='^';
      System.out.println("Value: "+val);
      if (Character.isLetterOrDigit(val)) {
         System.out.println("Value is a letter or digit!");
      }else {
         System.out.println("Value is neither a letter nor a digit!");
      }
   }
}

Output

Value: ^
Value is neither a letter nor a digit!

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

87 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements