Table of contents
1.
Introduction
2.
What is the isDigit Java function?
3.
Purpose and Usage of isDigit() in Java
4.
Syntax of isDigit() in Java
4.1.
First Form Syntax
4.1.1.
Parameter
4.1.2.
Return Value 
4.2.
Second Form Syntax: 
4.2.1.
Parameter
4.2.2.
Return Value 
5.
Parameters of isDigit() in Java
6.
Example of isDigit Java 
6.1.
Code in Java 
6.2.
java
6.2.1.
Output
6.3.
java
6.3.1.
Output
6.4.
Explanation
7.
Frequently Asked Questions
7.1.
How do you know if a character is 0 to 9?
7.2.
How to check if a character is an alphabet in Java?
7.3.
How to check a digit in Java?
7.4.
How to find a char is digit in Java?
8.
Conclusion
Last Updated: Jun 14, 2025
Easy

isDigit() in Java

Author Nikhil Joshi
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Have you ever written your own function to check whether a character is a digit in Java? Well, do you know that the Character wrapper class in Java provides the isDigit method precisely for that?

isDigit Java

In this article titled ‘isDigit Java’, we will discuss the intricacies of the isDigit function. Let’s start our journey!

Also read, Duck Number in Java and Hashcode Method in Java.

What is the isDigit Java function?

The isDigit java function is provided by the Character wrapper class. It is used to check whether a given character is a digit. Java checks for the value returned by Character.getType(ch). If the value returned is DECIMAL_DIGIT_NUMBER constant, then isDigit java returns true else, false.

Some Unicode ranges containing digits:

  1. ISO-Latin digits (0-9): ‘\u0030’ to ‘\u0039’.
     
  2. Arabic-Indic digits: ‘\u0660’’ to ‘\u0669’.
     
  3. Extended Arabic-Indic digits: ‘\u06F0’ to ‘\u06F9’.
     
  4. Devnagari digits: ‘\u0966’ to ‘\u096F’.
     
  5. Fullwidth digits: ‘\uFF10’ to ‘\uFF19’.

Purpose and Usage of isDigit() in Java

The isDigit() method in Java, provided by the Character class, is widely used to check whether a given character is a digit (0-9). Developers commonly use this method in scenarios where validating numeric input is crucial, such as form submissions, password checks, or user-entered data where numbers are expected. It is also helpful when parsing strings to extract numerical values, ensuring that only valid digit characters are processed, which helps prevent runtime errors.

Another practical application is filtering or separating digit characters from alphanumeric data, such as processing product codes, extracting phone numbers, or cleaning data inputs. Using isDigit() improves program reliability by ensuring non-digit characters are excluded from numerical operations, thereby reducing input-related bugs and data corruption.

Example:

char ch = '5';
if (Character.isDigit(ch)) {
    System.out.println(ch + " is a digit.");
} else {
    System.out.println(ch + " is not a digit.");
}

Syntax of isDigit() in Java

The Java isDigit function has two forms:

First Form Syntax

public static boolean isDigit(char ch)


This function takes character ch as input. Then it checks if it is a digit or not. This function does not work for supplementary characters.

Parameter

  • ch: This is the character you want to check if it's a digit or not. It's the input to the function, and you provide a single character (char) as an argument

Return Value 

  • The isDigit function returns a boolean value, which means it can be either true or false
     
  • If the provided character ch is a digit (0-9), the function returns true
     
  • If the character ch is not a digit (i.e., it's any other character), the function returns false

Second Form Syntax: 

public static boolean isDigit(int codePoint)


The function takes an integer “codepoint” as the parameter. This function can work for supplementary characters. Supplementary characters are characters of languages like Japanese and Chinese that can not be represented in Unicode-16.

Parameter

  • codePoint: This parameter represents an integer value that corresponds to a Unicode code point. A Unicode code point is a unique number assigned to each character in the Unicode standard. In this form of the isDigit method, you provide an integer value (code point) as the argument

Return Value 

  • Like the first form, the second form of the isDigit function also returns a boolean value (true or false)
     
  • If the specified codePoint corresponds to a digit character in the Unicode standard (0-9), the function returns true
     
  • If the codePoint does not represent a digit character, it returns false

Parameters of isDigit() in Java

The isDigit() method in Java, part of the Character class, is used to determine whether a character represents a digit. It accepts two types of parameters: a char or an int representing a Unicode codepoint. This allows the method to support both simple character checks and a broader range of international digit representations.

  • char ch: This version checks if the provided single character is a digit. It is commonly used for standard ASCII digits (0-9) but also supports digits from other numeral systems if the character is within the Unicode digit range.
  • int codePoint: This version allows checking Unicode codepoints directly, enabling support for digits from a wide variety of languages and numeral systems beyond the basic ASCII set.

The isDigit() method recognizes digits across multiple Unicode digit ranges, including but not limited to:

  • ISO-LATIN-1 digits: \u0030 to \u0039 (0-9)
  • Arabic-Indic digits: \u0660 to \u0669
  • Extended Arabic-Indic digits: \u06F0 to \u06F9
  • Devanagari digits: \u0966 to \u096F
  • Fullwidth digits: \uFF10 to \uFF19

These are just a few examples; the method supports many additional digit ranges defined in the Unicode standard, making it highly reliable for internationalization. By supporting codepoints, isDigit() ensures that digit validation works accurately across diverse languages and scripts.

Example of isDigit Java 

1. The following example demonstrates how we can use the isDigit Java function to find if a character is a digit.

Code in Java 

  • java

java

public class IsDigitExample {
   public static void main(String[] args) {
       // demonstration of isDigit java function
      
       // characters storing different values
       char n = '9';
       char a = 'a';
       char b = '*';
       char nn = '4';


       // checking if they are digit or not
       boolean result_n = Character.isDigit(n);
       boolean result_a = Character.isDigit(a);
       boolean result_b = Character.isDigit(b);
       boolean result_nn = Character.isDigit(nn);


       System.out.println("char "+n+" is a digit : "+result_n);
       System.out.println("char "+a+" is a digit : "+result_a);
       System.out.println("char "+b+" is a digit : "+result_b);
       System.out.println("char "+nn+" is a digit : "+result_nn);
   }
}

You can also try this code with Online Java Compiler
Run Code

 

Output

output


2. The following example shows how we can use the isDigit Java function to test if a given password contains both alphabet and numeric characters, i.e. the password is alphanumeric.

  • java

java

public class IsDigitExample {
   public static void main(String[] args) {
       // demonstration of isDigit Java  function used for testing if the password is alphanumeric or not


       // password string
       String password = "hsXsS97RrjhlLfm";


       // countDigits store num of digits present in the password
       int countDigits = 0;


       int passwordLength = password.length(); // password length


       for(int i=0; i<passwordLength; i++){
           char currentCharacter = password.charAt(i);


           // checking if current character is digit
           if(Character.isDigit(currentCharacter)){
               countDigits++;
           }
       }


       // if the number of digit present in the password string is equal to the password string length
       //That means it does not contain any alphabet
       boolean isAlphaNumeric = (countDigits != passwordLength);


       System.out.println("Password is : "+password);
       System.out.println("No of digits in password : "+countDigits);
       System.out.println("No of characters other than digits in password : "+(passwordLength-countDigits));
       System.out.println("Given password is : "+ ((isAlphaNumeric)? "Alphanumerical" : "All digits"));
   }
}

You can also try this code with Online Java Compiler
Run Code

 

Output

Output

Explanation

We are counting the number of digits present in the password string. If the number of digits is equal to the length of the password string, then the password does not contain any extra characters and hence is not alphanumeric. We are looping over the password character by character to count the number of digits.

Also see, Swap Function in Java

Frequently Asked Questions

How do you know if a character is 0 to 9?

To determine if a character is in the range of '0' to '9' (digits), you can use the condition (ch >= '0' && ch <= '9'). If ch falls within this range in the ASCII or Unicode character set, it represents a digit.

How to check if a character is an alphabet in Java?

Similar to the isDigit function in Java, we also have the isAlphabetic function available. This function can classify whether a given character is an alphabet.

How to check a digit in Java?

To check if a character is a digit in Java, you can use the Character.isDigit(char ch) method, which returns a boolean value true if ch is a digit (0-9).

How to find a char is digit in Java?

To find if a character is a digit in Java, use Character.isDigit(char ch). It returns true if ch is a digit (0-9).

Conclusion

In conclusion, the isDigit Java function, provided by the Character wrapper class, can classify a character as a digit. The function takes a character as the parameter and checks if it is a digit. Another function overloads the isDigit function, which takes an integer as the parameter. This overloading is done to classify supplementary characters, which are generally not used but are part of languages like Japanese and Chinese.

Following are some references for further readings in Java:

  1. Input method in Java 
  2. Java Hello World Program 
  3. Difference between While and Do While Loops
     
Live masterclass