Character.isLetterOrDigit() in Java with examples

The java.lang.Character.isLetterOrDigit(char ch) is an inbuilt method in java which determines if the specified character is a letter or digit.

Syntax:

public static boolean isLetterOrDigit(char ch)

Parameters: The function accepts a single mandatory parameter ch which signifies the character to be tested.



Return value: This function returns a boolean value. The boolean value is true if the character is a letter or digit else it false.

Below programs illustrate the above method:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate the
// Character.isLetterOrDigit() method
  
import java.lang.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // two characters
        char c1 = 'Z', c2 = '2';
  
        // Function to check if the character is letter or digit
        boolean bool1 = Character.isLetterOrDigit(c1);
        System.out.println(c1 + " is a letter/digit ? " + bool1);
  
        // Function to check if the character is letter or digit
        boolean bool2 = Character.isLetterOrDigit(c2);
        System.out.println(c2 + " is a letter/digit ? " + bool2);
    }
}

chevron_right


Output:

Z is a letter/digit ? true
2 is a letter/digit ? true

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate the
// Character.isLetterOrDigit() method
  
import java.lang.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // assign character
        char c1 = 'D', c2 = '/';
  
        // Function to check if the character is letter or digit
        boolean bool1 = Character.isLetterOrDigit(c1);
        System.out.println(c1 + " is a letter/digit ? " + bool1);
  
        // Function to check if the character is letter or digit
        boolean bool2 = Character.isLetterOrDigit(c2);
        System.out.println(c2 + " is a letter/digit ? " + bool2);
    }
}

chevron_right


Output:

D is a letter/digit ? true
/ is a letter/digit ? false

Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isLetterOrDigit(char)



My Personal Notes arrow_drop_up

Contented with little yet wishing for more

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.