Java Character isLetterOrDigit() Method
Example
Check if characters are letters or digits:
public class Main {
public static void main(String[] args) {
System.out.println(Character.isLetterOrDigit('A'));
System.out.println(Character.isLetterOrDigit('5'));
System.out.println(Character.isLetterOrDigit(' '));
System.out.println(Character.isLetterOrDigit('!'));
}
}
Definition and Usage
The isLetterOrDigit() method checks if a character is a letter or a digit. It returns false for spaces and symbols.
It gives the same result as Character.isLetter(c) || Character.isDigit(c). Use it, for example, to check that a user name has only letters and digits.
Syntax
One of the following:
public static boolean isLetterOrDigit(char ch)
public static boolean isLetterOrDigit(int codePoint)
Most programs use the first version, with a char. The second version takes the character as a code point (the number that Unicode gives each character), as an int.
Parameter Values
| Parameter | Description |
|---|---|
| ch | Required. The character to check. |
| codePoint | Required. The code point of the character to check. |
Technical Details
| Returns: | true if the character is a letter or a digit, otherwise false. |
|---|
Related Pages
❮ Character Methods