The isLetterOrDigit()
method is a static method in the Character
class in Java, which is used to determine if the specified character is a letter or digit.
A character is determined a letter or a digit when either of the Character.isLetter() or Character.isDigit() methods return true
.
public static boolean isLetterOrDigit(char ch)
char ch
- The character to be checked for letter or digit.
The isLetterOrDigit()
function returns true
if the character sent as a parameter is a letter or a digit; otherwise, it returns false
.
In the code below, we test the function against letters, digits and special characters.
public class Main{public static void main(String[] args){System.out.println(Character.isLetterOrDigit('a'));System.out.println(Character.isLetterOrDigit('1'));System.out.println(Character.isLetterOrDigit('9'));System.out.println(Character.isLetterOrDigit('Z'));System.out.println(Character.isLetterOrDigit('.'));System.out.println(Character.isLetterOrDigit('!'));}}