Character

Name

The Character class provides an object
wrapper for a char value. This is useful when
you need to treat a char value as an object.
For example, there are a number of utility methods that take a reference
to an Object as one of their arguments. You cannot
specify a char value for one of these arguments,
but you can provide a reference to a Character object
that encapsulates the char value. Furthermore,
as of JDK 1.1, the Character class is necessary to
support the Reflection API and class literals.

In Java, Character objects represent values defined
by the Unicode standard. Unicode is defined
by an organization called the Unicode Consortium. The defining document for
Unicode is The Unicode Standard, Version 2.0
(ISBN 0-201-48345-9). More recent information about Unicode is
available at http://unicode.org.
Appendix a, The Unicode 2.0 Character Set, contains a table that lists the characters
defined by the Unicode 2.0 standard.

The Character class provides some utility
methods, such as methods for determining the type (e.g., uppercase
or lowercase, digit or letter) of a character and for converting
from uppercase to lowercase. The logic for these utility methods
is based on a Unicode attribute table that is part of the Unicode
standard. That table is available at
ftp://unicode.org/pub/2.0-Update/UnicodeData-2.0.14.txt.

Some of the methods in the Character class
are concerned with characters that are digits; these characters are used by
a number of other classes to convert strings that contain numbers
into actual numeric values. The digit-related methods all use a
radix value to interpret characters.
The radix is the numeric base used to represent numbers
as characters or strings. Octal is a radix 8 representation, while
hexadecimal is a radix 16 representation. The methods that require
a radix parameter use it to determine which characters
should be treated as valid digits. In radix 2, only the characters
`0' and `1' are valid digits. In radix 16, the characters `0' through
`9', `a' through `z', and `A' through `Z' are considerd valid digits.

public final class java.lang.Character extends java.lang.Object
implements java.io.Serializable {
// Constants
public final static byte COMBINING_SPACING_MARK; // New in 1.1
public final static byte CONNECTOR_PUNCTUATION; // New in 1.1
public final static byte CONTROL; // New in 1.1
public final static byte CURRENCY_SYMBOL; // New in 1.1
public final static byte DASH_PUNCTUATION; // New in 1.1
public final static byte DECIMAL_DIGIT_NUMBER; // New in 1.1
public final static byte ENCLOSING_MARK; // New in 1.1
public final static byte END_PUNCTUATION; // New in 1.1
public final static byte FORMAT; // New in 1.1
public final static byte LETTER_NUMBER; // New in 1.1
public final static byte LINE_SEPARATOR; // New in 1.1
public final static byte LOWERCASE_LETTER; // New in 1.1
public final static byte MATH_SYMBOL; // New in 1.1
public final static int MAX_RADIX;
public final static char MAX_VALUE;
public final static int MIN_RADIX;
public final static char MIN_VALUE;
public final static byte MODIFIER_LETTER; // New in 1.1
public final static byte MODIFIER_SYMBOL; // New in 1.1
public final static byte NON_SPACING_MARK; // New in 1.1
public final static byte OTHER_LETTER; // New in 1.1
public final static byte OTHER_NUMBER; // New in 1.1
public final static byte OTHER_PUNCTUATION; // New in 1.1
public final static byte OTHER_SYMBOL; // New in 1.1
public final static byte PARAGRAPH_SEPARATOR; // New in 1.1
public final static byte PRIVATE_USE; // New in 1.1
public final static byte SPACE_SEPARATOR; // New in 1.1
public final static byte START_PUNCTUATION; // New in 1.1
public final static byte SURROGATE; // New in 1.1
public final static byte TITLECASE_LETTER; // New in 1.1
public final static Class TYPE; // New in 1.1
public final static byte UNASSIGNED; // New in 1.1
public final static byte UPPERCASE_LETTER; // New in 1.1
// Constructors
public Character(char value);
// Class Methods
public static int digit(char ch, int radix);
public static char forDigit(int digit, int radix);
public static int getNumericValue(char ch); // New in 1.1
public static int getType(char ch); // New in 1.1
public static boolean isDefined(char ch);
public static boolean isDigit(char ch);
public static boolean isIdentifierIgnorable(char ch); // New in 1.1
public static boolean isISOControl(char ch); // New in 1.1
public static boolean isJavaIdentifierPart(char ch); // New in 1.1
public static boolean isJavaIdentifierStart(char ch); // New in 1.1
public static boolean isJavaLetter(char ch); // Deprecated in 1.1
public static boolean isJavaLetterOrDigit(char ch); // Deprecated in 1.1
public static boolean isLetter(char ch);
public static boolean isLetterOrDigit(char ch);
public static boolean isLowerCase(char ch);
public static boolean isSpace(char ch); // Deprecated in 1.1
public static boolean isSpaceChar(char ch); // New in 1.1
public static boolean isTitleCase(char ch);
public static boolean isUnicodeIdentifierPart(char ch); // New in 1.1
public static boolean isUnicodeIdentifierStart(char ch);// New in 1.1
public static boolean isUpperCase(char ch);
public static boolean isWhitespace(char ch); // New in 1.1
public static char toLowerCase(char ch);
public static char toTitleCase(char ch);
public static char toUpperCase(char ch);
// Instance Methods
public char charValue();
public boolean equals(Object obj);
public int hashCode();
public String toString();
}

The radix used in interpreting the specified character
as a digit. If radix is in the range 2 through
10, only characters for which the isDigit() method
returns true are considered to be valid digits.
If radix is in the range 11 through 36, characters
in the ranges `A' through `Z' and `a' through `z' may be considered
valid digits.

Returns

The numeric value of the digit. This method returns -1 if
the value of ch is not considered a valid digit,
if radix is less than MIN_RADIX,
or if radix is greater than MAX_RADIX.

Description

Returns the numeric value represented by a digit character.
For example, digit('7',10) returns 7. If the
value of ch is not a valid digit, the method
returns -1. For example,
digit('7',2) returns
-1 because '7' is not a valid digit in radix 2. A number of methods
in other classes use this method to convert strings that contain
numbers to actual numeric values. The forDigit() method
is an approximate inverse of this method.

If radix is greater than 10, characters
in the range `A' to `A'+radix-11 are treated
as valid digits. Such a character has the numeric value ch-`A'+10.
By the same token, if radix is greater than 10,
characters in the range `a' to `a'+radix-11 are
treated as valid digits. Such a character has the numeric value
ch-`a'+10.

The character that represents the digit corresponding to the specified
numeric value. The method returns `\ 0' if digit is
less than 0, if digit is equal to or greater than
radix, if radix is less than
MIN_RADIX, or if radix is
greater than MAX_RADIX.

Description

This method returns the character that represents the digit
corresponding to the specified numeric value. If digit
is in the range 0 through 9, the method returns `0'+digit.
If digit is in the range 10
through MAX_RADIX-1,
the method returns `a'+digit-10. The method
returns `\ 0' if digit is less than 0, if
digit
is equal to or greater than radix,
if radix is less than MIN_RADIX,
or if radix is greater than MAX_RADIX.

The Unicode numeric value of the character as a nonnegative
integer. This method returns -1 if the character has no numeric
value; it returns -2 if the character has a numeric value that is
not a nonnegative integer, such as 1/2.

Description

This method returns the Unicode numeric value of the specified
character as a nonnegative integer.

true if the specified character is an ISO
control character; otherwise false.

Description

This method determines whether or not the specified character is an
ISO control character. A character is an ISO control character if
it falls in the range \u0000
through \u001F or \u007F
through \u009F.

true if the specified character can appear after the
first character in a Java identifier; otherwise false.

Description

This method returns true if the specified character
can appear in a Java identifier after the first character. A character
is considered part of a Java identifier if and only if it is a letter,
a digit, a currency symbol (e.g., $), a connecting punctuation
character (e.g., _), a numeric letter (e.g., a
Roman numeral), a combining mark, a nonspacing mark, or an ignorable
control character.

true if the specified character can appear as the
first character in a Java identifier; otherwise false.

Description

This method returns true if the specified character
can appear in a Java identifier as the first character. A character
is considered a start of a Java identifier if and only if it is a letter,
a currency symbol (e.g., $), or a connecting punctuation character
(e.g., _).

true if the specified character can appear
as the first character in a Java identifier;
otherwise false.

Description

This method returns true if the specified
character can appear as the first character in a Java identifier.
A character is considered a Java letter if and only if it is a letter,
the character $, or the character _ .
This method returns false for digits because digits are not
allowed as the first character of an identifier.

This method is deprecated as of JDK 1.1. You should use
isJavaIdentifierStart() instead.

true if the specified character can appear
after the first character in a Java identifier;
otherwise false.

Description

This method returns true if the specified
character can appear in a Java identifier after the
first character. A character is considered a Java letter or digit
if and only if it is a letter, a digit, the character $,
or the character _.

This method is deprecated as of JDK 1.1. You should use
isJavaIdentifierPart() instead.

true if the specified character is defined
as a letter in the Unicode character set; otherwise false.

Description

This method determines whether or not the specified character
is a letter, based on the definition of the character in Unicode.
This method does not consider character values in ranges that
have not been assigned meanings by Unicode to be letters.

true if the specified character is defined
as a letter in the Unicode character set; otherwise false.

Description

This method determines whether or not the specified character
is a letter or a digit, based on the definition of the character
in Unicode.
There are some ranges that have not been assigned meanings by
Unicode. If a character value is in one of these ranges, this method
does not consider the character to be a letter.

true if the specified character is defined
as lowercase in the Unicode character set; otherwise false.

Description

This method determines whether or not the specified character
is lowercase. Unicode defines a number of characters that do not
have case mappings; if the specified character is one of these characters,
the method returns false.

true if the specified character is a Unicode 2.0 space
characters; otherwise false.

Description

This method determines if the specified character
is a space character according to the Unicode 2.0 specification.
A character is considered to be a Unicode space character if and only
if it has the general category "Zs", "Zl", or "Zp" in the
Unicode specification.

true if the specified character is defined
as titlecase in the Unicode character set; otherwise false.

Description

This method determines whether or not the specified character
is a titlecase character. Unicode defines a number of characters that do not
have case mappings; if the specified character is one of these characters,
the method returns false.

Many characters are defined by the Unicode standard as having
upper- and lowercase forms. There are some characters defined
by the Unicode standard that also have a titlecase form. The glyphs
for these characters look like a combination of two Latin letters.
The titlecase form of these characters has a glyph that looks like
a combination of an uppercase Latin character and a lowercase
Latin character; this case should be used when the character appears
as the first character of a word in a title. For example, one of
the Unicode characters that has a titlecase form looks like the
letter `D' followed by the letter `Z'. Here is what the three forms
of this letter look like:

true if the specified character can appear after the
first character in a Unicode identifier; otherwise false.

Description

This method returns true if the specified character
can appear in a Unicode identifier after the first character. A character
is considered part of a Unicode identifier if and only if it is a letter,
a digit, a connecting punctuation character
(e.g., _), a numeric letter (e.g., a Roman numeral), a combining mark,
a nonspacing mark, or an ignorable control character.

true if the specified character is defined
as uppercase in the Unicode character set; otherwise false.

Description

This method determines whether or not the specified character
is uppercase. Unicode defines a number of characters that do not
have case mappings; if the specified character is one of these characters,
the method returns false.

The lowercase equivalent of the specified character, or the
character itself if it cannot be converted to lowercase.

Description

This method returns the lowercase equivalent of the specified
character value. If the specified character is not uppercase or
if it has no lowercase equivalent, the character is returned unmodified.
The Unicode attribute table determines if a character has a mapping
to a lowercase equivalent.

Some Unicode characters in the range \u2000
through \u2FFF have lowercase mappings. For
example, \u2160 (Roman numeral one) has a lowercase
mapping to \u2170 (small Roman numeral one).
The toLowerCase() method maps such characters
to their lowercase equivalents even though the method isUpperCase()
does not return true for such characters.

The titlecase equivalent of the specified character, or the
character itself if it cannot be converted to titlecase.

Description

This method returns the titlecase equivalent of the specified
character value. If the specified character has no titlecase equivalent,
the character is returned unmodified. The Unicode attribute table
is used to determine the character's titlecase equivalent.

Many characters are defined by the Unicode standard as having
upper- and lowercase forms. There are some characters defined
by the Unicode standard that also have a titlecase form. The glyphs
for these characters look like a combination of two Latin letters.
The titlecase form of these characters has a glyph that looks like
a combination of an uppercase Latin character and a lowercase
Latin character; this case should be used when the character appears
as the first character of a word in a title. For example, one of
the Unicode characters that has a titlecase form looks like the
letter `D' followed by the letter `Z'. Here is what the three forms
of this letter look like:

The uppercase equivalent of the specified character, or the
character itself if it cannot be converted to uppercase.

Description

This method returns the uppercase equivalent of the specified
character value. If the specified character is not lowercase or
if it has no uppercase equivalent, the character is returned unmodified.
The Unicode attribute table determines if a character has a mapping
to an uppercase equivalent.

Some Unicode characters in the range \u2000
through \u2FFF have uppercase mappings. For
example, \u2170 (small Roman numeral one) has
a lowercase mapping to \u2160 (Roman numeral
one). The toUpperCase() method maps such characters
to their uppercase equivalents even though the method isLowerCase()
does not return true for such characters.