Home »
Java programming language
Java - Character Class isDigit() Method
Character class isDigit() method: Here, we are going to learn about the isDigit() method of Character class with its syntax and example.
By Preeti Jain Last updated : March 17, 2024
Character class isDigit() method
- isDigit() method is available in java.lang package.
- isDigit() method is used to check whether the given char value is a digit or not.
- isDigit() method does not throw an exception at the time of checking the given char value is a digit or not.
Syntax
public boolean isDigit(Char c);
Parameters
- Char c – represents the char value to be checked.
Return Value
The return type of this method is boolean, it returns a boolean value based on the following cases,
- It returns true, if the given char value is digit.
- It returns false, if the given char value is not digit.
Example
// Java program to demonstrate the example
// of boolean isDigit (Char c) method of Character class
public class IsDigitOfCharacterClass {
public static void main(String[] args) {
// It returns false because the passing
// character is not digit
boolean result1 = Character.isDigit('a');
// It returns true because the passing
// character is a digit
boolean result2 = Character.isDigit('7');
// Display values of result1 , result2
System.out.println("Character.isDigit('a'): " + result1);
System.out.println("Character.isDigit('7'): " + result2);
}
}
Output
Character.isDigit('a'): false
Character.isDigit('7'): true