java.lang.Character getNumericValue(int codePoint)
Description
The letters A-Z in their uppercase (‘u0041’ through ‘u005A’), lowercase (‘u0061’ through ‘u007A’), and full width variant (‘uFF21’ through ‘uFF3A’ and ‘uFF41’ through ‘uFF5A’) forms have numeric values from 10 through 35. This is independent of the Unicode specification, which does not assign numeric values to these char values.
If the character does not have a numeric value, then -1 is returned. If the character has a numeric value that cannot be represented as a nonnegative integer (for example, a fractional value), then -2 is returned.
The getNumericValue(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.getNumericValue(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 getNumericValue() method non statically.
Method Syntax
public static int getNumericValue(int codePoint)
Method Argument
Data Type | Parameter | Description |
---|---|---|
int | codePoint | the character (Unicode code point) to be converted. |
Method Returns
The getNumericValue(int codePoint) method of Character class returns an int which denotes the numeric value of the character, as a nonnegative int value; -2 if the character has a numeric value that is not a nonnegative integer; -1 if the character has no numeric value.
Compatibility
Requires Java 1.5 and up
Java Character getNumericValue(int codePoint) Example
Below is a simple java example on the usage of getNumericValue(int codePoint) method of Character class.
package com.javatutorialhq.java.examples; /* * This example source code demonstrates the use of * getNumericValue(int codePoint) method of Character class. */ public class CharacterGetNumericValueCodepointExample { public static void main(String[] args) { // initialize a codepoint int codepoint = 65; // convert codepoint to char char ch = (char) codepoint; // convert the code point to its numeric value int digit = Character.getNumericValue(codepoint); // print the result System.out.println("character '" + ch + "' numeric value is " + digit); } }
Sample Output
Below is the sample output when you run the above example.