check if char is alphabet java code example

Example 1: how to check if a char is a letter java

Character.isDigit(string.charAt(index)) //(JavaDoc) will return true if it's a digit
Character.isLetter(string.charAt(index)) //(JavaDoc) will return true if it's a letter

Example 2: character is alphabet or not in java

class Main {
  public static void main(String[] args) {

    // declare a variable
    char c = 'a';

    // checks if c is an alphabet
    if (Character.isAlphabetic(c)) {
      System.out.println(c + " is an alphabet.");
    }
    else {
      System.out.println(c + " is not an alphabet.");
    }
  }
}

Tags:

Java Example