|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Character
The 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 the type of a character and converting characters from uppercase to lowercase and vice versa.
Many of the methods of class Character
are defined
in terms of a "Unicode attribute table" that specifies
a name for every defined Unicode code point. The table also
includes other attributes, such as a decimal value, an uppercase
equivalent, a lowercase equivalent, and/or a titlecase equivalent.
The character attribute tables for specific versions of Unicode
are available on the World Wide Web in various subdirectories of:
ftp://ftp.unicode.org/Public/
For a more detailed specification of the Character
class, one that encompasses the exact behavior of methods such as
isDigit
, isLetter
,
isLowerCase
, and isUpperCase
over the
full range of Unicode values, see Gosling, Joy, and Steele, The
Java Language Specification.
Inner Class Summary | |
static class |
Character.Subset
Instances of this class represent particular subsets of the Unicode character set. |
static class |
Character.UnicodeBlock
A family of character subsets representing the character blocks defined by the Unicode 2.0 specification. |
Field Summary | |
static byte |
COMBINING_SPACING_MARK
Public data for enumerated Unicode general category types |
static byte |
CONNECTOR_PUNCTUATION
Public data for enumerated Unicode general category types |
static byte |
CONTROL
Public data for enumerated Unicode general category types |
static byte |
CURRENCY_SYMBOL
Public data for enumerated Unicode general category types |
static byte |
DASH_PUNCTUATION
Public data for enumerated Unicode general category types |
static byte |
DECIMAL_DIGIT_NUMBER
Public data for enumerated Unicode general category types |
static byte |
ENCLOSING_MARK
Public data for enumerated Unicode general category types |
static byte |
END_PUNCTUATION
Public data for enumerated Unicode general category types |
static byte |
FORMAT
Public data for enumerated Unicode general category types |
static byte |
LETTER_NUMBER
Public data for enumerated Unicode general category types |
static byte |
LINE_SEPARATOR
Public data for enumerated Unicode general category types |
static byte |
LOWERCASE_LETTER
Public data for enumerated Unicode general category types |
static byte |
MATH_SYMBOL
Public data for enumerated Unicode general category types |
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 . |
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 . |
static byte |
MODIFIER_LETTER
Public data for enumerated Unicode general category types |
static byte |
MODIFIER_SYMBOL
Public data for enumerated Unicode general category types |
static byte |
NON_SPACING_MARK
Public data for enumerated Unicode general category types |
static byte |
OTHER_LETTER
Public data for enumerated Unicode general category types |
static byte |
OTHER_NUMBER
Public data for enumerated Unicode general category types |
static byte |
OTHER_PUNCTUATION
Public data for enumerated Unicode general category types |
static byte |
OTHER_SYMBOL
Public data for enumerated Unicode general category types |
static byte |
PARAGRAPH_SEPARATOR
Public data for enumerated Unicode general category types |
static byte |
PRIVATE_USE
Public data for enumerated Unicode general category types |
static byte |
SPACE_SEPARATOR
Public data for enumerated Unicode general category types |
static byte |
START_PUNCTUATION
Public data for enumerated Unicode general category types |
static byte |
SURROGATE
Public data for enumerated Unicode general category types |
static byte |
TITLECASE_LETTER
Public data for enumerated Unicode general category types |
static Class |
TYPE
The Class object representing the primitive type char. |
static byte |
UNASSIGNED
Public data for enumerated Unicode general category types |
static byte |
UPPERCASE_LETTER
Public data for enumerated Unicode general category types |
Constructor Summary | |
Character(char value)
Constructs a Character object and initializes it so
that it represents the primitive value argument. |
Method Summary | |
char |
charValue()
Returns the value of this Character object. |
int |
compareTo(Character anotherCharacter)
Compares two Characters numerically. |
int |
compareTo(Object o)
Compares this Character to another Object. |
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. |
static int |
getNumericValue(char ch)
Returns the Unicode numeric value of the character as a nonnegative integer. |
static int |
getType(char ch)
Returns a value indicating a character category. |
int |
hashCode()
Returns a hash code for this Character. |
static boolean |
isDefined(char ch)
Determines if a character has a defined meaning in Unicode. |
static boolean |
isDigit(char ch)
Determines if the specified character is a digit. |
static boolean |
isIdentifierIgnorable(char ch)
Determines if the specified character should be regarded as an ignorable character in a Java identifier or a Unicode identifier. |
static boolean |
isISOControl(char ch)
Determines if the specified character is an ISO control character. |
static boolean |
isJavaIdentifierPart(char ch)
Determines if the specified character may be part of a Java identifier as other than the first character. |
static boolean |
isJavaIdentifierStart(char ch)
Determines if the specified character is permissible as the first character in a Java identifier. |
static boolean |
isJavaLetter(char ch)
Deprecated. Replaced by isJavaIdentifierStart(char). |
static boolean |
isJavaLetterOrDigit(char ch)
Deprecated. Replaced by isJavaIdentifierPart(char). |
static boolean |
isLetter(char ch)
Determines if the specified character is a letter. |
static boolean |
isLetterOrDigit(char ch)
Determines if the specified character is a letter or digit. |
static boolean |
isLowerCase(char ch)
Determines if the specified character is a lowercase character. |
static boolean |
isSpace(char ch)
Deprecated. Replaced by isWhitespace(char). |
static boolean |
isSpaceChar(char ch)
Determines if the specified character is a Unicode space character. |
static boolean |
isTitleCase(char ch)
Determines if the specified character is a titlecase character. |
static boolean |
isUnicodeIdentifierPart(char ch)
Determines if the specified character may be part of a Unicode identifier as other than the first character. |
static boolean |
isUnicodeIdentifierStart(char ch)
Determines if the specified character is permissible as the first character in a Unicode identifier. |
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 char |
toTitleCase(char ch)
Converts the character argument to titlecase. |
static char |
toUpperCase(char ch)
Converts the character argument to uppercase. |
Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final int MIN_RADIX
digit
method, the forDigit
method, and the toString
method of class
Integer
.public static final int MAX_RADIX
digit
method, the forDigit
method, and the toString
method of class
Integer
.public static final char MIN_VALUE
char
.public static final char MAX_VALUE
char
.public static final Class TYPE
public static final byte UNASSIGNED
public static final byte UPPERCASE_LETTER
public static final byte LOWERCASE_LETTER
public static final byte TITLECASE_LETTER
public static final byte MODIFIER_LETTER
public static final byte OTHER_LETTER
public static final byte NON_SPACING_MARK
public static final byte ENCLOSING_MARK
public static final byte COMBINING_SPACING_MARK
public static final byte DECIMAL_DIGIT_NUMBER
public static final byte LETTER_NUMBER
public static final byte OTHER_NUMBER
public static final byte SPACE_SEPARATOR
public static final byte LINE_SEPARATOR
public static final byte PARAGRAPH_SEPARATOR
public static final byte CONTROL
public static final byte FORMAT
public static final byte PRIVATE_USE
public static final byte SURROGATE
public static final byte DASH_PUNCTUATION
public static final byte START_PUNCTUATION
public static final byte END_PUNCTUATION
public static final byte CONNECTOR_PUNCTUATION
public static final byte OTHER_PUNCTUATION
public static final byte MATH_SYMBOL
public static final byte CURRENCY_SYMBOL
public static final byte MODIFIER_SYMBOL
public static final byte OTHER_SYMBOL
Constructor Detail |
public Character(char value)
Character
object and initializes it so
that it represents the primitive value
argument.value
- value for the new Character
object.Method Detail |
public char charValue()
char
value represented by
this object.public int hashCode()
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.obj
- the object to compare with.true
if the objects are the same;
false
otherwise.public String toString()
Character
object to a string. The
result is a string whose length is 1
. The string's
sole component is the primitive char
value represented
by this object.public static boolean isLowerCase(char ch)
'\u2000'
through '\u2FFF'
, the Unicode
attribute table does not specify a mapping to lowercase for the
character, and at least one of the following is true:
SMALL
LETTER
".
SMALL
LIGATURE
".
A character is considered to be lowercase if and only if it is specified to be lowercase by the Unicode 2.0 standard (category "Ll" in the Unicode specification data file).
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
Many other Unicode characters are lowercase, too.
ch
- the character to be tested.true
if the character is lowercase;
false
otherwise.isLowerCase(char)
,
isTitleCase(char)
,
toLowerCase(char)
public static boolean isUpperCase(char ch)
'\u2000'
through '\u2FFF'
, the Unicode
attribute table does not specify a mapping to uppercase for the
character, and at least one of the following is true:
CAPITAL LETTER
".
CAPITAL LIGATURE
".
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
Many other Unicode characters are uppercase, too.
ch
- the character to be tested.true
if the character is uppercase;
false
otherwise.isLowerCase(char)
,
isTitleCase(char)
,
toUpperCase(char)
public static boolean isTitleCase(char ch)
The printed representations of four Unicode characters look like pairs of Latin letters. For example, there is an uppercase letter that looks like "LJ" and has a corresponding lowercase letter that looks like "lj". A third form, which looks like "Lj", is the appropriate form to use when rendering a word in lowercase with initial capitals, as for a book title.
These are the Unicode characters for which this method returns
true
:
LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON
LATIN CAPITAL LETTER L WITH SMALL LETTER J
LATIN CAPITAL LETTER N WITH SMALL LETTER J
LATIN CAPITAL LETTER D WITH SMALL LETTER Z
ch
- the character to be tested.true
if the character is titlecase;
false
otherwise.isLowerCase(char)
,
isUpperCase(char)
,
toTitleCase(char)
public static boolean isDigit(char ch)
'\u2000' <= ch <= '\u2FFF'
and its Unicode name contains the word
"DIGIT
". For a more complete
specification that encompasses all Unicode characters that are
defined as digits, see Gosling, Joy, and Steele, The Java
Language Specification.
These are the ranges of Unicode characters that are considered digits:
0x0030 through 0x0039 | ISO-LATIN-1 digits ('0' through '9') |
0x0660 through 0x0669 | Arabic-Indic digits |
0x06F0 through 0x06F9 | Extended Arabic-Indic digits |
0x0966 through 0x096F | Devanagari digits |
0x09E6 through 0x09EF | Bengali digits |
0x0A66 through 0x0A6F | Gurmukhi digits |
0x0AE6 through 0x0AEF | Gujarati digits |
0x0B66 through 0x0B6F | Oriya digits |
0x0BE7 through 0x0BEF | Tamil digits |
0x0C66 through 0x0C6F | Telugu digits |
0x0CE6 through 0x0CEF | Kannada digits |
0x0D66 through 0x0D6F | Malayalam digits |
0x0E50 through 0x0E59 | Thai digits |
0x0ED0 through 0x0ED9 | Lao digits |
0x0F20 through 0x0F29 | Tibetan digits |
0xFF10 through 0xFF19 | Fullwidth digits |
ch
- the character to be tested.true
if the character is a digit;
false
otherwise.digit(char, int)
,
forDigit(int, int)
public static boolean isDefined(char ch)
'\u3040' <= ch <= '\u9FA5'
.
'\uF900' <= ch <= '\uFA2D'
.
ch
- the character to be testedtrue
if the character has a defined meaning
in Unicode; false
otherwise.isDigit(char)
,
isLetter(char)
,
isLetterOrDigit(char)
,
isLowerCase(char)
,
isTitleCase(char)
,
isUpperCase(char)
public static boolean isLetter(char ch)
A character is considered to be a letter if and only if it is specified to be a letter by the Unicode 2.0 standard (category "Lu", "Ll", "Lt", "Lm", or "Lo" in the Unicode specification data file).
Note that most ideographic characters are considered to be letters (category "Lo") for this purpose.
Note also that not all letters have case: many Unicode characters are letters but are neither uppercase nor lowercase nor titlecase.
ch
- the character to be tested.true
if the character is a letter;
false
otherwise.isDigit(char)
,
isJavaIdentifierStart(char)
,
isJavaLetter(char)
,
isJavaLetterOrDigit(char)
,
isLetterOrDigit(char)
,
isLowerCase(char)
,
isTitleCase(char)
,
isUnicodeIdentifierStart(char)
,
isUpperCase(char)
public static boolean isLetterOrDigit(char ch)
A character is considered to be a letter if and only if it is specified to be a letter or a digit by the Unicode 2.0 standard (category "Lu", "Ll", "Lt", "Lm", "Lo", or "Nd" in the Unicode specification data file). In other words, isLetterOrDigit is true of a character if and only if either isLetter is true of the character or isDigit is true of the character.
ch
- the character to be tested.true
if the character is a letter or digit;
false
otherwise.isDigit(char)
,
isJavaIdentifierPart(char)
,
isJavaLetter(char)
,
isJavaLetterOrDigit(char)
,
isLetter(char)
,
isUnicodeIdentifierPart(char)
public static boolean isJavaLetter(char ch)
A character is considered to be a Java letter if and only if it
is a letter, the ASCII dollar sign character '$'
, or
the underscore character '_'
.
ch
- the character to be tested.true
if the character is a Java letter;
false
otherwise.isJavaIdentifierStart(char)
,
isJavaLetterOrDigit(char)
,
isLetter(char)
,
isLetterOrDigit(char)
,
isUnicodeIdentifierStart(char)
public static boolean isJavaLetterOrDigit(char ch)
A character is considered to be a Java letter or digit if and
only if it is a letter, a digit, the ASCII dollar sign character
'$'
, or the underscore character '_'
.
ch
- the character to be tested.true
if the character is a Java letter or digit;
false
otherwise.isJavaIdentifierPart(char)
,
isJavaLetter(char)
,
isLetter(char)
,
isLetterOrDigit(char)
,
isUnicodeIdentifierPart(char)
public static boolean isJavaIdentifierStart(char ch)
ch
- the character to be tested.isJavaIdentifierPart(char)
,
isLetter(char)
,
isUnicodeIdentifierStart(char)
public static boolean isJavaIdentifierPart(char ch)
ch
- the character to be tested.isIdentifierIgnorable(char)
,
isJavaIdentifierStart(char)
,
isLetterOrDigit(char)
,
isUnicodeIdentifierPart(char)
public static boolean isUnicodeIdentifierStart(char ch)
ch
- the character to be tested.isJavaIdentifierStart(char)
,
isLetter(char)
,
isUnicodeIdentifierPart(char)
public static boolean isUnicodeIdentifierPart(char ch)
ch
- the character to be tested.isIdentifierIgnorable(char)
,
isJavaIdentifierPart(char)
,
isLetterOrDigit(char)
,
isUnicodeIdentifierStart(char)
public static boolean isIdentifierIgnorable(char ch)
0x0000 through 0x0008, | ISO control characters that |
0x000E through 0x001B, | are not whitespace |
and 0x007F through 0x009F | |
0x200C through 0x200F | join controls |
0x200A through 0x200E | bidirectional controls |
0x206A through 0x206F | format controls |
0xFEFF | zero-width no-break space |
ch
- the character to be tested.isJavaIdentifierPart(char)
,
isUnicodeIdentifierPart(char)
public static char toLowerCase(char ch)
A character has a lowercase equivalent if and only if a lowercase mapping is specified for the character in the Unicode attribute table.
Note that some Unicode characters in the range
'\u2000'
to '\u2FFF'
have lowercase
mappings; this method does map such characters to their lowercase
equivalents even though the method isUpperCase
does
not return true
for such characters.
ch
- the character to be converted.isLowerCase(char)
,
isUpperCase(char)
,
toTitleCase(char)
,
toUpperCase(char)
public static char toUpperCase(char ch)
Note that some Unicode characters in the range
'\u2000'
to '\u2000FFF'
have uppercase
mappings; this method does map such characters to their titlecase
equivalents even though the method isLowerCase
does
not return true
for such characters.
ch
- the character to be converted.isLowerCase(char)
,
isUpperCase(char)
,
toLowerCase(char)
,
toTitleCase(char)
public static char toTitleCase(char ch)
Note that some Unicode characters in the range
'\u2000'
through '\u2FFF'
have titlecase
mappings; this method does map such characters to their titlecase
equivalents even though the method isTitleCase
does
not return true
for such characters.
There are only four Unicode characters that are truly titlecase forms that are distinct from uppercase forms. As a rule, if a character has no true titlecase equivalent but does have an uppercase mapping, then the Unicode 2.0 attribute table specifies a titlecase mapping that is the same as the uppercase mapping.
ch
- the character to be converted.isTitleCase(char)
,
toLowerCase(char)
,
toUpperCase(char)
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.forDigit(int, int)
,
isDigit(char)
public static int getNumericValue(char ch)
ch
- the character to be converted.forDigit(int, int)
,
isDigit(char)
public static boolean isSpace(char ch)
true
for the following five
characters only:
'\t' | \u0009 | HORIZONTAL TABULATION |
'\n' | \u000A | NEW LINE |
'\f' | \u000C | FORM FEED |
'\r' | \u000D | CARRIAGE RETURN |
' ' | \u0020 | SPACE |
ch
- the character to be tested.true
if the character is ISO-LATIN-1 white
space; false
otherwise.isSpaceChar(char)
,
isWhitespace(char)
public static boolean isSpaceChar(char ch)
ch
- the character to be tested.isWhitespace(char)
public static boolean isWhitespace(char ch)
ch
- the character to be tested.isSpaceChar(char)
public static boolean isISOControl(char ch)
ch
- the character to be tested.isSpaceChar(char)
,
isWhitespace(char)
public static int getType(char ch)
ch
- the character to be tested.COMBINING_SPACING_MARK
,
CONNECTOR_PUNCTUATION
,
CONTROL
,
CURRENCY_SYMBOL
,
DASH_PUNCTUATION
,
DECIMAL_DIGIT_NUMBER
,
ENCLOSING_MARK
,
END_PUNCTUATION
,
FORMAT
,
LETTER_NUMBER
,
LINE_SEPARATOR
,
LOWERCASE_LETTER
,
MATH_SYMBOL
,
MODIFIER_LETTER
,
MODIFIER_SYMBOL
,
NON_SPACING_MARK
,
OTHER_LETTER
,
OTHER_NUMBER
,
OTHER_PUNCTUATION
,
OTHER_SYMBOL
,
PARAGRAPH_SEPARATOR
,
PRIVATE_USE
,
SPACE_SEPARATOR
,
START_PUNCTUATION
,
SURROGATE
,
TITLECASE_LETTER
,
UNASSIGNED
,
UPPERCASE_LETTER
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)
public int compareTo(Character anotherCharacter)
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 int compareTo(Object o)
compareTo(Character)
. Otherwise, it throws a
ClassCastException
(as Characters are
comparable only to other Characters).o
- the Object
to be compared.0
if the argument is a Character
numerically equal to this Character; a value less than
0
if the argument is a Character numerically
greater than this Character; and a value greater than
0
if the argument is a Character numerically
less than this Character.ClassCastException
- if the argument is not a
Character
.Comparable
|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |