Name
Character
Synopsis
This class provides an immutable
object wrapper around the primitive char
data
type. charValue( )
returns the
char
value of a Character
object. The compareTo(
)
method
implements the Comparable
interface so that
Character
objects can be ordered and sorted. The
static methods are the most interesting thing about this class,
however: they categorize char
values based on the
categories defined by the Unicode
standard. (Some
of the methods are only useful if you have a detailed understanding
of that standard.) Static methods beginning with
“is” test
whether
a character is in a
given category. isDigit(
)
, isLetter( )
,
isWhitespace( )
, isUpperCase( )
and isLowerCase( )
are some of the most useful.
Note that these methods work for any Unicode character, not just with
the familiar Latin letters and Arabic numbers of the ASCII character
set. getType( )
returns
a constant that identifies the category of a character.
getDirectionality(
)
returns a separate
DIRECTIONALITY_
constant that specifies the
“directionality category” of a
character.
In addition to testing the category of a character, this class also
defines static methods for converting characters.
toUpperCase( )
returns the uppercase equivalent of the
specified character (or returns the character itself if the character
is uppercase or has no uppercase equivalent). toLowerCase(
)
converts instead to lowercase.
digit( )
returns the integer equivalent of a given character in a given radix (or base; ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.