Java Character isLetter() method Example

Java Character API comes with many methods to test whether a character is a digit or letter etc. This type of testing is useful in situations like constraints on passwords, employee id etc.

To test for letter, the character class comes with isLetter(char) method.

Following is the method signature as defined in java.lang.Character class.

  • public static boolean isLetter(char ch): Checks the specified character ch is a letter or not. The method returns true if the char ch is a letter else false.

Following Java Character isLetter() method Example illustrates. Just for interest, special characters are also checked.

public class CharacterFunctionDemo
  public static void main(String args[])
   char ch1 = 'A';
   char ch2 = '5';                      

   boolean b1 = Character.isLetter(ch1);
   boolean b2 = Character.isLetter(ch2);

   System.out.println(ch1 + " is letter: " + b1);     
   System.out.println(ch2 + " is letter: " + b2);     

   System.out.println("\n+ is letter: " + Character.isLetter('+'));
   System.out.println("$ is digit: " + Character.isLetter('$'));

Java Character isLetter() method Example
Output screenshot on Java Character isLetter() method Example

Practice other methods of Java Character, Math, String, StringBuffer classes to get command over Java coding as a Developer.

Leave a Comment

Your email address will not be published.