Signup/Sign In

Java Character isLetterOrDigit(int codePoint) Method

Java isLetterOrDigit(int codePoint) method is a part of Character class. This method is used to check whether the specified Unicode codepoint character is a letter or a digit.

A character can be considered as a letter or a digit if either Character.isLetter(char ch) or Character.isDigit(char ch) returns true for the character.

Syntax:

public static boolean isLetterOrDigit(int codePoint)

Parameters:

The parameter passed is the Unicode codePoint character to be checked for digit or letter.

Returns:

Returns the boolean value true if the specified character is a digit or a letter else return false.

Example 1:

Here, the characters are checked whether they are a letter or digit or not.

public class StudyTonight
{  
	public static void main(String[] args)
	{  
		int cp1 = 48;  
		int cp2 = 61;  
		int cp3 = 119;  
		int cp4 = 90;   
		int cp5 = 1232;  

		boolean b1 = Character.isLetterOrDigit(cp1);  
		boolean b2 = Character.isLetterOrDigit(cp2);  
		boolean b3 = Character.isLetterOrDigit(cp3);  
		boolean b4 = Character.isLetterOrDigit(cp4);  
		boolean b5 = Character.isLetterOrDigit(cp5);  

		System.out.println((char)cp1 +" is a letter or digit??:  "+b1);  
		System.out.println((char)cp2 +" is a letter or digit??:  "+b2);  
		System.out.println((char)cp3 +" is a letter or digit??:  "+b3);  
		System.out.println((char)cp4 +" is a letter or digit??:  "+b4);  
		System.out.println((char)cp5 +" is a letter or digit??:  "+b5);  
	}  
} 


0 is a letter or digit??: true
= is a letter or digit??: false
w is a letter or digit??: true
Z is a letter or digit??: true
? is a letter or digit??: true

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.

import java.util.Scanner; 
public class StudyTonight
{  
	public static void main(String[] args)
	{  
		try
		{
			System.out.print("Enter the Unicode character: ");  
			Scanner sc = new Scanner(System.in);        
			int cp = sc.nextInt(); 
			boolean b = Character.isLetterOrDigit(cp);
			System.out.println((char)cp + " is a  Letter or digit?: "+b);
		}
		catch(Exception e)
		{
			System.out.println("Invalid Input!!");
		}
	}  
}


Enter the Unicode character: 77
M is a Letter or digit?: true
***************************************
Enter the Unicode character: 44
, is a Letter or digit?: false

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.



About the author:
A Computer Science and Engineering Graduate(2016-2020) from JSSATE Noida. JAVA is Love. Sincerely Followed Sachin Tendulkar as a child, M S Dhoni as a teenager, and Virat Kohli as an adult.