Way2Java

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.

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('$'));
  }
}



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.