java.lang.Character isLetter(char ch)
Description
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 case. Many characters are letters but are neither uppercase nor lowercase nor titlecase.
This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the isLetter(int) method.
The isLetter(char ch) method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:
Character.isLetter(char ch)
Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java isLetter() method non statically.
Method Syntax
public static boolean isLetter(char ch)
Method Argument
Data Type | Parameter | Description |
---|---|---|
char | ch | the character to be tested. |
Method Returns
The isLetter(char ch) method of Character class returns true if the character is a letter; false otherwise.
Compatibility
Requires Java 1.0 and up
Java Character isLetter(char ch) Example
Below is a simple java example on the usage of isLetter(char ch) method of Character class.
package com.javatutorialhq.java.examples; import java.util.Scanner; /* * This example source code demonstrates the use of * isLetter(char ch) method of Character class. */ public class CharacterIsLetterCharExample { public static void main(String[] args) { // Ask for user input System.out.print("Enter a character:"); // use scanner to get the user input Scanner s = new Scanner(System.in); // get a single character char value = s.nextLine().toCharArray()[0]; // close the scanner object s.close(); // check if the user input is a letter or not boolean checkBool = Character.isLetter(value); // print result if(checkBool){ System.out.print("User input '"+value+"' is a letter"); } else{ System.out.print("User input '"+value+"' is not a letter"); } } }
Sample Output
Below is the sample output when you run the above example.