How to use isDigit() method in java?

The isDigit(char ch) method determines whether the specified char value is a digit or not. It returns true if the passed character is a digit.

Syntax-

public static boolean isDigit(char ch)

This isDigit() method accepts character parameter ch as an argument, which is to be tested and returns a boolean value. It returns True if ch is a digit, else False.

There are few conditions that a character must accomplish to be accepted as a digit. That is if the general category type of a character, provided by Character.getType(ch), is DECIMAL_DIGIT_NUMBER, then the character is a digit.
Some Unicode character ranges that contain digits:

  • From '\u0030' to '\u0039' : ISO-LATIN-1 digits ('0' through '9')
  • From '\u0660' to '\u0669' : Arabic-Indic digits
  • From '\u06F0' to '\u06F9' : Extended Arabic-Indic digits
  • From '\u0966' to '\u096F' : Devanagari digits
  • From '\uFF10' to '\uFF19' : Fullwidth digits
 public static void main(String[] args) {

   // two characters
   char c1 = 'A', c2 = '3';

   System.out.println( c1 + " is a digit ? " +Character.isDigit(c1));
   System.out.println(c2 + " is a digit ? " +Character.isDigit(c2));
 }

Output-

A is a digit ? false  
3 is a digit ? true 

isDigit(int codePoint) -

The isDigit(int codePoint) determines if the specified character (Unicode code point) is a digit or not. A codePoint is a number that identifies a symbol. Two well-known standards for assigning numbers to symbols are ASCII and Unicode. ASCII defines 128 symbols. Unicode currently defines 109384 symbols,

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

syntax-

public static boolean isDigit(int codePoint)  

The above method requires only one parameter which is the codePoint which is a Unicode character that needs to be tested and returns a boolean value i.e. true if the given(or specified) character is a digit. Otherwise, the method returns false.

public static void main(String[] args)
    {
        // create codePoints
        int cp1 = 57;
        int cp2 = 84;
  
        // Check whether the codePoints
        // are digit or not.
        
        //57 is the decimal value that represnts the character 9 which is a digit
        System.out.println("The codePoint 57 is a digit ? "+ Character.isDigit(cp1));

        //84 is the decimal value that represnts the character T which is not a digit
        System.out.println("The codePoint 84 is a digit ? "+ Character.isDigit(cp2));
    }

Output-

The codePoint 57 is a digit ? true
The codePoint 84 is a digit ? false 
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions