isLetterOrDigit() method in Java

Java 8Object Oriented ProgrammingProgramming

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!
raja
Published on 13-Nov-2018 10:14:57

Advertisements