public final class Character extends Object implements Comparable<Character>
Character
class wraps a value of the primitive
type char
in an object. An object of type
Character
contains a single field whose type is
char
.
In addition, this class provides several methods for determining a character's category (lowercase letter, digit, etc.) and for converting characters from uppercase to lowercase and vice versa.
Character information is based on the Unicode Standard, version 6.2.0.
The methods and data of class Character
are defined by
the information in the UnicodeData file that is part of the
Unicode Character Database maintained by the Unicode
Consortium. This file specifies various properties including name
and general category for every defined Unicode code point or
character range.
The file and its description are available from the Unicode Consortium at:
The char
data type (and therefore the value that a
Character
object encapsulates) are based on the
original Unicode specification, which defined characters as
fixed-width 16-bit entities. The Unicode Standard has since been
changed to allow for characters whose representation requires more
than 16 bits. The range of legal code points is now
U+0000 to U+10FFFF, known as Unicode scalar value.
(Refer to the
definition of the U+n notation in the Unicode
Standard.)
The set of characters from U+0000 to U+FFFF is
sometimes referred to as the Basic Multilingual Plane (BMP).
Characters whose code points are greater
than U+FFFF are called supplementary characters. The Java
platform uses the UTF-16 representation in char
arrays and
in the String
and StringBuffer
classes.
A char
value, therefore, represents Basic
Multilingual Plane (BMP) code points, including the surrogate
code points, or code units of the UTF-16 encoding. An
int
value represents all Unicode code points,
including supplementary code points. The lower (least significant)
21 bits of int
are used to represent Unicode code
points and the upper (most significant) 11 bits must be zero.
The methods that only accept a char
value cannot support
supplementary characters.
This specification supports only the Basic Multilingual Plane (BMP)
and does NOT support code points
greater than U+FFFF
.
In the Java SE API documentation, Unicode code unit is used for 16-bit
char
values that are code units of the UTF-16
encoding. For more information on Unicode terminology, refer to the
Unicode Glossary.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_RADIX
The maximum radix available for conversion to and from strings.
|
static char |
MAX_VALUE
The constant value of this field is the largest value of type
char , '\uFFFF' . |
static int |
MIN_RADIX
The minimum radix available for conversion to and from strings.
|
static char |
MIN_VALUE
The constant value of this field is the smallest value of type
char , '\u0000' . |
static int |
SIZE
The number of bits used to represent a char value in unsigned
binary form, constant
16 . |
static Class<Character> |
TYPE
The
Class instance representing the primitive type
char . |
Constructor and Description |
---|
Character(char value)
Constructs a newly allocated
Character object that
represents the specified char value. |
Modifier and Type | Method and Description |
---|---|
char |
charValue()
Returns the value of this
Character object. |
int |
compareTo(Character anotherCharacter)
Compares two
Character objects numerically. |
static int |
digit(char ch,
int radix)
Returns the numeric value of the character
ch in the
specified radix. |
boolean |
equals(Object obj)
Compares this object against the specified object.
|
static char |
forDigit(int digit,
int radix)
Determines the character representation for a specific digit in
the specified radix.
|
int |
hashCode()
Returns a hash code for this
Character ; equal to the result
of invoking charValue() . |
static boolean |
isDigit(char ch)
Determines if the specified character is a digit.
|
static boolean |
isISOControl(char ch)
Determines if the specified character is an ISO control
character.
|
static boolean |
isLowerCase(char ch)
Determines if the specified character is a lowercase character.
|
static boolean |
isSpaceChar(char ch)
Determines if the specified character is a Unicode space character.
|
static boolean |
isUpperCase(char ch)
Determines if the specified character is an uppercase character.
|
static boolean |
isWhitespace(char ch)
Determines if the specified character is white space according to Java.
|
static char |
toLowerCase(char ch)
The given character is mapped to its lowercase equivalent; if the
character has no lowercase equivalent, the character itself is
returned.
|
String |
toString()
Returns a
String object representing this
Character 's value. |
static String |
toString(char c)
Returns a
String object representing the
specified char . |
static char |
toUpperCase(char ch)
Converts the character argument to uppercase; if the
character has no uppercase equivalent, the character itself is
returned.
|
static Character |
valueOf(char c)
Returns a Character instance representing the specified
char value.
|
public static final int MAX_RADIX
digit
method, the forDigit
method, and the
toString
method of class Integer
.public static final char MAX_VALUE
char
, '\uFFFF'
.public static final int MIN_RADIX
digit
method, forDigit
method, and the
toString
method of class Integer
.public static final char MIN_VALUE
char
, '\u0000'
.public static final int SIZE
16
.public Character(char value)
Character
object that
represents the specified char
value.value
- the value to be represented by the
Character
object.public char charValue()
Character
object.char
value represented by
this object.public int compareTo(Character anotherCharacter)
Character
objects numerically.compareTo
in interface Comparable<Character>
anotherCharacter
- the Character
to be compared.0
if the argument Character
is equal to this Character
; a value less than
0
if this Character
is numerically less
than the Character
argument; and a value greater than
0
if this Character
is numerically greater
than the Character
argument (unsigned comparison).
Note that this is strictly a numerical comparison; it is not
locale-dependent.public static int digit(char ch, int radix)
ch
in the
specified radix.
If the radix is not in the range MIN_RADIX
≤
radix
≤ MAX_RADIX
or if the
value of ch
is not a valid digit in the specified
radix, -1
is returned. A character is a valid digit
if at least one of the following is true:
isDigit
is true
of the character
and the Unicode decimal digit value of the character (or its
single-character decomposition) is less than the specified radix.
In this case the decimal digit value is returned.
'A'
through 'Z'
and its code is less than
radix + 'A' - 10
.
In this case, ch - 'A' + 10
is returned.
'a'
through 'z'
and its code is less than
radix + 'a' - 10
.
In this case, ch - 'a' + 10
is returned.
ch
- the character to be converted.radix
- the radix.isDigit(char)
,
forDigit(int, int)
public boolean equals(Object obj)
true
if and only if the argument is not
null
and is a Character
object that
represents the same char
value as this object.equals
in class Object
obj
- the object to compare with.true
if the objects are the same;
false
otherwise.Object.hashCode()
,
HashMap
public static char forDigit(int digit, int radix)
radix
is not a
valid radix, or the value of digit
is not a valid
digit in the specified radix, the null character
('\u0000'
) is returned.
The radix
argument is valid if it is greater than or
equal to MIN_RADIX
and less than or equal to
MAX_RADIX
. The digit
argument is valid if
0 <= digit < radix
.
If the digit is less than 10, then
'0' + digit
is returned. Otherwise, the value
'a' + digit - 10
is returned.
digit
- the number to convert to a character.radix
- the radix.char
representation of the specified digit
in the specified radix.MIN_RADIX
,
MAX_RADIX
,
digit(char, int)
,
forDigit(int, int)
public int hashCode()
Character
; equal to the result
of invoking charValue()
.hashCode
in class Object
Character
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public static boolean isDigit(char ch)
ch
- the character to be tested.true
if the character is a digit;
false
otherwise.digit(char, int)
public static boolean isISOControl(char ch)
'\u0000'
through '\u001F'
or in the range
'\u007F'
through '\u009F'
.ch
- the character to be tested.true
if the character is an ISO control character;
false
otherwise.isSpaceChar(char)
,
isWhitespace(char)
public static boolean isLowerCase(char ch)
Note that by default CLDC only supports the ISO Latin-1 range of characters.
Of the ISO Latin-1 characters (character codes 0x0000 through 0x00FF), the following are lowercase:
a b c d e f g h i j k l m n o p q r s t u v w x y z '\u00DF' '\u00E0' '\u00E1' '\u00E2' '\u00E3' '\u00E4' '\u00E5' '\u00E6' '\u00E7' '\u00E8' '\u00E9' '\u00EA' '\u00EB' '\u00EC' '\u00ED' '\u00EE' '\u00EF' '\u00F0' '\u00F1' '\u00F2' '\u00F3' '\u00F4' '\u00F5' '\u00F6' '\u00F8' '\u00F9' '\u00FA' '\u00FB' '\u00FC' '\u00FD' '\u00FE' '\u00FF'
ch
- the character to be tested.true
if the character is lowercase;
false
otherwise.isLowerCase(char)
,
toLowerCase(char)
public static boolean isSpaceChar(char ch)
ch
- the character to be tested.true
if the character is a space character;
false
otherwise.isWhitespace(char)
public static boolean isUpperCase(char ch)
Note that by default CLDC only supports the ISO Latin-1 range of characters.
Of the ISO Latin-1 characters (character codes 0x0000 through 0x00FF), the following are uppercase:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z '\u00C0' '\u00C1' '\u00C2' '\u00C3' '\u00C4' '\u00C5' '\u00C6' '\u00C7' '\u00C8' '\u00C9' '\u00CA' '\u00CB' '\u00CC' '\u00CD' '\u00CE' '\u00CF' '\u00D0' '\u00D1' '\u00D2' '\u00D3' '\u00D4' '\u00D5' '\u00D6' '\u00D8' '\u00D9' '\u00DA' '\u00DB' '\u00DC' '\u00DD' '\u00DE'
ch
- the character to be tested.true
if the character is uppercase;
false
otherwise.isLowerCase(char)
public static boolean isWhitespace(char ch)
SPACE_SEPARATOR
,
LINE_SEPARATOR
, or PARAGRAPH_SEPARATOR
)
but is not also a non-breaking space ('\u00A0'
,
'\u2007'
, '\u202F'
).
'\t'
, U+0009 HORIZONTAL TABULATION.
'\n'
, U+000A LINE FEED.
'\u000B'
, U+000B VERTICAL TABULATION.
'\f'
, U+000C FORM FEED.
'\r'
, U+000D CARRIAGE RETURN.
'\u001C'
, U+001C FILE SEPARATOR.
'\u001D'
, U+001D GROUP SEPARATOR.
'\u001E'
, U+001E RECORD SEPARATOR.
'\u001F'
, U+001F UNIT SEPARATOR.
ch
- the character to be tested.true
if the character is a Java whitespace
character; false
otherwise.isSpaceChar(char)
public static char toLowerCase(char ch)
Note that by default CLDC only supports the ISO Latin-1 range of characters.
In general, String.toLowerCase()
should be used to map
characters to lowercase. String
case mapping methods
have several benefits over Character
case mapping methods.
String
case mapping methods can perform locale-sensitive
mappings, context-sensitive mappings, and 1:M character mappings, whereas
the Character
case mapping methods cannot.
ch
- the character to be converted.isLowerCase(char)
,
String.toLowerCase()
public String toString()
String
object representing this
Character
's value. The result is a string of
length 1 whose sole component is the primitive
char
value represented by this
Character
object.public static String toString(char c)
String
object representing the
specified char
. The result is a string of length
1 consisting solely of the specified char
.c
- the char
to be convertedchar
public static char toUpperCase(char ch)
Note that by default CLDC only supports the ISO Latin-1 range of characters.
ch
- the character to be converted.isUpperCase(char)
,
String.toUpperCase()
public static Character valueOf(char c)
Character(char)
, as this method is likely to yield
significantly better space and time performance by caching
frequently requested values.c
- a char value.Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. Use of this specification is subject to license terms.