java.lang.Character isDigit(int codePoint)
Description
A character is a digit if its general category type, provided by getType(codePoint), is DECIMAL_DIGIT_NUMBER.
Some Unicode character ranges that contain digits:
- ‘u0030’ through ‘u0039’, ISO-LATIN-1 digits (‘0’ through ‘9’)
- ‘u0660’ through ‘u0669’, Arabic-Indic digits
- ‘u06F0’ through ‘u06F9’, Extended Arabic-Indic digits
- ‘u0966’ through ‘u096F’, Devanagari digits
- ‘uFF10’ through ‘uFF19’, Fullwidth digits
Many other character ranges contain digits as well.
The isDigit(int codePoint) method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:
Character.isDigit(int codePoint)
Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java isDigit() method non statically.
Method Syntax
public static boolean isDigit(int codePoint)
Method Argument
Data Type | Parameter | Description |
---|---|---|
int | codepoint | the character (Unicode code point) to be tested. |
Method Returns
The isDigit(int codePoint) method of Character class returns true if the character is a digit; false otherwise.
Compatibility
Requires Java 1.5 and up
Java Character isDigit(int codePoint) Example
Below is a simple java example on the usage of isDigit(int codePoint) method of Character class.
package com.javatutorialhq.java.examples; /* * This example source code demonstrates the use of * isDigit(int codePoint) method of Character class. */ public class CharacterIsDigitCodepointExample { public static void main(String[] args) { // initialize a codepoint int codepoint = 49; // check if the codepoint is digit or not boolean checkBool = Character.isDigit(codepoint); // print result if(checkBool){ System.out.print("Codepoint '"+codepoint+"' is a digit"); } else{ System.out.print("Codepoint '"+codepoint+"' is not a digit"); } } }
Sample Output
Below is the sample output when you run the above example.