Javatpoint Logo
Javatpoint Logo

Java Character isDigit() Method

The isDigit(int codePoint) method of Character class generally determines whether the given character is a digit or not. Generally, a character is considered as a digit if its general category given by getType(codePoint), is DECIMAL_DIGIT_NUMBER.

Syntax

Parameter

The above method requires only one parameter:

a.)The codePoint which is a Unicode character that needs to be tested.

Return Value

The isDigit(int codePoint) method returns a boolean value i.e. true, if the given(or specified) character is a digit. Otherwise, the method returns false.

Example 1

Test it Now

Output:

The codePoint '55' is a digit.
The codePoint '32' is not a digit.
The codePoint '121' is not a digit.
The codePoint '49' is a digit.
The codePoint '200' is not a digit.

Example 2

Test it Now

Output:

The first object represents a digit :  true
The first object represents a digit :  false
The first object represents a digit :  false
The first object represents a digit :  false

Java Character isDigit() Method

The isDigit(char ch) method of Character class generally determines whether the given character is a digit or not.

Generally, a character is considered as a digit if its general category given by Character.getType(ch), is DECIMAL_DIGIT_NUMBER.

Note: The above method cannot be used to handle the supplementary characters. In order to support all the Unicode characters, including all the supplementary characters, we can use the isdigit(int) method.

Syntax

Parameter

The above method requires only one parameter

a.)The character that needs to be tested.

Return Value

The isDigit(char ch) method returns a boolean value, i.e., true if the given(or specified) character is a digit. Otherwise, the method returns false.

Example 3

Test it Now

Output:

The digit ' ' is:false
The digit '4' is:true
The digit '8' is:true

Example 4

Test it Now

Output:

Enter the first character: &
The character '&' is not a digit.
Enter the first character: 3
The character '3' is a digit.

Example 5

Test it Now

Output:

The digit 'A' is:false
The digit '3' is:true
The digit 'b' is:false
The digit '6' is:true

Next TopicJava Character




Please Share

facebook twitter google plus pinterest