Java Reference
In-Depth Information
8.5.
Character
The
Character
class represents the
char
type as a class. It provides meth-
ods for determining the type of a character (letter, digit, uppercase, and
so forth) and for converting between uppercase and lowercase.
Since a
char
is a 16-bit value, and Unicode allows for 21-bit characters,
known as
code points,
many of the methods of
Character
are overloaded
to take either a
char
or an
int
that represents an arbitrary code point.
Such methods are described in combination below and the pseudo-type
codePoint
is used to represent either a
char
or an
int
code point value.
In addition to
MIN_VALUE
and
MAX_VALUE
constants,
Character
provides the
constants
MIN_RADIX
and
MAX_RADIX
, which are the minimum and maximum
radices understood by methods that translate between digit characters
and integer values or vice versa,. The radix must be in the range 236;
digits for values greater than 9 are the letters
A
tHRough
Z
or their lower-
case equivalents. Three methods convert between characters and integer
values:
public static int
digit(
codePoint
ch, int radix)
Returns the numeric value of
ch
considered as a digit in the
given radix. If the radix is not valid or if
ch
is not a digit in the
radix, 1 is returned. For example,
digit('A',16)
returns 10 and
digit('9',10)
returns 9, while
digit('a',10)
returns 1.
public static int
getNumericValue(
codePoint
ch)
Returns the numeric value of the digit
ch
. For example, the
character
\u217F
is the Roman numeral digit
M
, so
getNumer-
icValue('\u217F')
returns the value 1000. These numeric val-
ues are non-negative. If
ch
has no numeric value, 1 is re-
turned; if it has a value but is not a non-negative integer, such
as the fractional value
ΒΌ
(
'\u00bc'
),
getNumericValue
returns 2.