Javatpoint Logo
Javatpoint Logo

Java Character getNumericValue() Method

The getNumericValue() method of character class returns the int value of the specified character. If the character does not have any int value, -1 is returned. If the character has a numeric value that cannot be represented as a non-negative integer, -2 is returned.

Syntax

Parameter

The above method requires only one parameter:

The codePoint is the character(Unicode code point) to be converted.

Return Value

The getNumericValue(int codePoint) method returns the numeric value of the character, as a non-negative int value. This method will return -2 if the character has a numeric value but the value cannot be represented as a non-negative int value. The method will return -1 if the character has no numeric value..

Example 1

Test it Now

Output:

The character 'n' has a numeric value represented as: 23

Example 2

Test it Now

Output:

Numeric value for code point obj1 is 33
Numeric value for code point obj2 is -1

Example 3

Test it Now

Output:

The character 'n' has a numeric value represented as: 23
The character ' ' has a numeric value represented as: -1
The character '6' has a numeric value represented as: 6
Next TopicJava Character



Help Others, Please Share

facebook twitter pinterest