Signup/Sign In
LAST UPDATED: NOVEMBER 24, 2020

Java Character isLetter(char ch) Method

Java isLetter(char ch) method is a part of Character class. This method is used to check whether the specified character is a letter.

A character is considered to be a letter if its general category type, provided by Character.getType(ch), is any of the following:

  • UPPERCASE_LETTER
  • LOWERCASE_LETTER
  • TITLECASE_LETTER
  • MODIFIER_LETTER
  • OTHER_LETTER

Not all letters have a case. Many characters are letters but are neither uppercase nor lowercase nor title case.

Syntax:

public static boolean isLetter(char ch)

Parameters:

The parameter passed is the character to be checked for a letter.

Returns:

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

Example 1:

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

public class StudyTonight
{ 
	public static void main(String[] args)
	{  
		char ch1 = ':';  
		char ch2 = 'D';  
		char ch3 = '8';  
		char ch4  = 'w';   
		char ch5  = '%';  

		boolean b1 = Character.isLetter(ch1);  
		boolean b2 = Character.isLetter(ch2);  
		boolean b3 = Character.isLetter(ch3);  
		boolean b4 = Character.isLetter(ch4);  
		boolean b5 = Character.isLetter(ch5);  

		System.out.println(ch1 +" is a letter??:  "+b1);  
		System.out.println(ch2 +" is a letter??:  "+b2);  
		System.out.println(ch3 +" is a letter??:  "+b3);  
		System.out.println(ch4 +" is a letter?? : "+b4);  
		System.out.println(ch5 +" is a letter??:  "+b5);  
	}  
} 


: is a letter??: false
D is a letter??: true
8 is a letter??: false
w is a letter?? : true
% is a letter??: false

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 character: ");  
			Scanner sc = new Scanner(System.in);         
			char ch = sc.next().charAt(0);  
			boolean b = Character.isLetter(ch);
			System.out.println(ch + " is a Letter?: "+b);
		}
		catch(Exception e)
		{
			System.out.println("Invalid Input!!");
		}
	}  
}


Enter the character: 6
6 is a Letter?: false
*****************************
Enter the character: u
u is a Letter?: true

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.