java.lang
Class Character

java.lang.Object
  extended by java.lang.Character
All Implemented Interfaces:
Comparable

public final class Character
extends Object
implements Comparable

Wrapper class for the primitive char data type. In addition, this class allows one to retrieve property information and perform transformations on the 57,707 defined characters in the Unicode Standard, Version 3.0.0. java.lang.Character is designed to be very dynamic, and as such, it retrieves information on the Unicode character set from a separate database, gnu.java.lang.CharData, which can be easily upgraded.

For predicates, boundaries are used to describe the set of characters for which the method will return true. This syntax uses fairly normal regular expression notation. See 5.13 of the Unicode Standard, Version 3.0, for the boundary specification.

See http://www.unicode.org for more information on the Unicode Standard.

Since:
1.0

Field Summary
static byte COMBINING_SPACING_MARK
          Mc = Mark, Spacing Combining (Normative).
static byte CONNECTOR_PUNCTUATION
          Pc = Punctuation, Connector (Informative).
static byte CONTROL
          Cc = Other, Control (Normative).
static byte CURRENCY_SYMBOL
          Sc = Symbol, Currency (Informative).
static byte DASH_PUNCTUATION
          Pd = Punctuation, Dash (Informative).
static byte DECIMAL_DIGIT_NUMBER
          Nd = Number, Decimal Digit (Normative).
static byte ENCLOSING_MARK
          Me = Mark, Enclosing (Normative).
static byte END_PUNCTUATION
          Pe = Punctuation, Close (Informative).
static byte FINAL_QUOTE_PUNCTUATION
          Pf = Punctuation, Final Quote (Informative).
static byte FORMAT
          Cf = Other, Format (Normative).
static byte INITIAL_QUOTE_PUNCTUATION
          Pi = Punctuation, Initial Quote (Informative).
static byte LETTER_NUMBER
          Nl = Number, Letter (Normative).
static byte LINE_SEPARATOR
          Zl = Separator, Line (Normative).
static byte LOWERCASE_LETTER
          Ll = Letter, Lowercase (Informative).
static byte MATH_SYMBOL
          Sm = Symbol, Math (Informative).
static int MAX_RADIX
          Largest value allowed for radix arguments in Java.
static char MAX_VALUE
          The maximum value the char data type can hold.
static int MIN_RADIX
          Smallest value allowed for radix arguments in Java.
static char MIN_VALUE
          The minimum value the char data type can hold.
static byte MODIFIER_LETTER
          Lm = Letter, Modifier (Informative).
static byte MODIFIER_SYMBOL
          Sk = Symbol, Modifier (Informative).
static byte NON_SPACING_MARK
          Mn = Mark, Non-Spacing (Normative).
static byte OTHER_LETTER
          Lo = Letter, Other (Informative).
static byte OTHER_NUMBER
          No = Number, Other (Normative).
static byte OTHER_PUNCTUATION
          Po = Punctuation, Other (Informative).
static byte OTHER_SYMBOL
          So = Symbol, Other (Informative).
static byte PARAGRAPH_SEPARATOR
          Zp = Separator, Paragraph (Normative).
static byte PRIVATE_USE
          Co = Other, Private Use (Normative).
static int SIZE
          The number of bits needed to represent a char.
static byte SPACE_SEPARATOR
          Zs = Separator, Space (Normative).
static byte START_PUNCTUATION
          Ps = Punctuation, Open (Informative).
static byte SURROGATE
          Cs = Other, Surrogate (Normative).
static byte TITLECASE_LETTER
          Lt = Letter, Titlecase (Informative).
static Class TYPE
          Class object representing the primitive char data type.
static byte UNASSIGNED
          Cn = Other, Not Assigned (Normative).
static byte UPPERCASE_LETTER
          Lu = Letter, Uppercase (Informative).
 
Constructor Summary
Character(char value)
          Wraps up a character.
 
Method Summary
 char charValue()
          Returns the character which has been wrapped by this class.
 int compareTo(Character anotherCharacter)
          Compares another Character to this Character, numerically.
 int compareTo(Object o)
          Compares an object to this Character.
static int digit(char ch, int radix)
          Converts a character into a digit of the specified radix.
 boolean equals(Object o)
          Determines if an object is equal to this object.
static char forDigit(int digit, int radix)
          Converts a digit into a character which represents that digit in a specified radix.
 int hashCode()
          Returns the numerical value (unsigned) of the wrapped character.
static boolean isDigit(char ch)
          Determines if a character is a Unicode decimal digit.
static boolean isLetter(char ch)
          Determines if a character is a Unicode letter.
static boolean isLetterOrDigit(char ch)
          Determines if a character is a Unicode letter or a Unicode digit.
static boolean isLowerCase(char ch)
          Determines if a character is a Unicode lowercase letter.
static boolean isSpace(char ch)
          Deprecated. Replaced by isWhitespace(char)
static boolean isSpaceChar(char ch)
          Determines if a character is a Unicode space character.
static boolean isUpperCase(char ch)
          Determines if a character is a Unicode uppercase letter.
static boolean isWhitespace(char ch)
          Determines if a character is Java whitespace.
static char reverseBytes(char val)
          Reverse the bytes in val.
static char toLowerCase(char ch)
          Converts a Unicode character into its lowercase equivalent mapping.
 String toString()
          Converts the wrapped character into a String.
static String toString(char ch)
          Returns a String of length 1 representing the specified character.
static char toUpperCase(char ch)
          Converts a Unicode character into its uppercase equivalent mapping.
static Character valueOf(char val)
          Returns an Character object wrapping the value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_RADIX

public static final int MIN_RADIX
Smallest value allowed for radix arguments in Java. This value is 2.

See Also:
digit(char, int), forDigit(int, int), Integer.toString(int, int), Integer.valueOf(String), Constant Field Values

MAX_RADIX

public static final int MAX_RADIX
Largest value allowed for radix arguments in Java. This value is 36.

See Also:
digit(char, int), forDigit(int, int), Integer.toString(int, int), Integer.valueOf(String), Constant Field Values

MIN_VALUE

public static final char MIN_VALUE
The minimum value the char data type can hold. This value is '\\u0000'.

See Also:
Constant Field Values

MAX_VALUE

public static final char MAX_VALUE
The maximum value the char data type can hold. This value is '\\uFFFF'.

See Also:
Constant Field Values

TYPE

public static final Class TYPE
Class object representing the primitive char data type.

Since:
1.1

SIZE

public static final int SIZE
The number of bits needed to represent a char.

Since:
1.5
See Also:
Constant Field Values

UPPERCASE_LETTER

public static final byte UPPERCASE_LETTER
Lu = Letter, Uppercase (Informative).

Since:
1.1
See Also:
Constant Field Values

LOWERCASE_LETTER

public static final byte LOWERCASE_LETTER
Ll = Letter, Lowercase (Informative).

Since:
1.1
See Also:
Constant Field Values

TITLECASE_LETTER

public static final byte TITLECASE_LETTER
Lt = Letter, Titlecase (Informative).

Since:
1.1
See Also:
Constant Field Values

NON_SPACING_MARK

public static final byte NON_SPACING_MARK
Mn = Mark, Non-Spacing (Normative).

Since:
1.1
See Also:
Constant Field Values

COMBINING_SPACING_MARK

public static final byte COMBINING_SPACING_MARK
Mc = Mark, Spacing Combining (Normative).

Since:
1.1
See Also:
Constant Field Values

ENCLOSING_MARK

public static final byte ENCLOSING_MARK
Me = Mark, Enclosing (Normative).

Since:
1.1
See Also:
Constant Field Values

DECIMAL_DIGIT_NUMBER

public static final byte DECIMAL_DIGIT_NUMBER
Nd = Number, Decimal Digit (Normative).

Since:
1.1
See Also:
Constant Field Values

LETTER_NUMBER

public static final byte LETTER_NUMBER
Nl = Number, Letter (Normative).

Since:
1.1
See Also:
Constant Field Values

OTHER_NUMBER

public static final byte OTHER_NUMBER
No = Number, Other (Normative).

Since:
1.1
See Also:
Constant Field Values

SPACE_SEPARATOR

public static final byte SPACE_SEPARATOR
Zs = Separator, Space (Normative).

Since:
1.1
See Also:
Constant Field Values

LINE_SEPARATOR

public static final byte LINE_SEPARATOR
Zl = Separator, Line (Normative).

Since:
1.1
See Also:
Constant Field Values

PARAGRAPH_SEPARATOR

public static final byte PARAGRAPH_SEPARATOR
Zp = Separator, Paragraph (Normative).

Since:
1.1
See Also:
Constant Field Values

CONTROL

public static final byte CONTROL
Cc = Other, Control (Normative).

Since:
1.1
See Also:
Constant Field Values

FORMAT

public static final byte FORMAT
Cf = Other, Format (Normative).

Since:
1.1
See Also:
Constant Field Values

SURROGATE

public static final byte SURROGATE
Cs = Other, Surrogate (Normative).

Since:
1.1
See Also:
Constant Field Values

PRIVATE_USE

public static final byte PRIVATE_USE
Co = Other, Private Use (Normative).

Since:
1.1
See Also:
Constant Field Values

UNASSIGNED

public static final byte UNASSIGNED
Cn = Other, Not Assigned (Normative).

Since:
1.1
See Also:
Constant Field Values

MODIFIER_LETTER

public static final byte MODIFIER_LETTER
Lm = Letter, Modifier (Informative).

Since:
1.1
See Also:
Constant Field Values

OTHER_LETTER

public static final byte OTHER_LETTER
Lo = Letter, Other (Informative).

Since:
1.1
See Also:
Constant Field Values

CONNECTOR_PUNCTUATION

public static final byte CONNECTOR_PUNCTUATION
Pc = Punctuation, Connector (Informative).

Since:
1.1
See Also:
Constant Field Values

DASH_PUNCTUATION

public static final byte DASH_PUNCTUATION
Pd = Punctuation, Dash (Informative).

Since:
1.1
See Also:
Constant Field Values

START_PUNCTUATION

public static final byte START_PUNCTUATION
Ps = Punctuation, Open (Informative).

Since:
1.1
See Also:
Constant Field Values

END_PUNCTUATION

public static final byte END_PUNCTUATION
Pe = Punctuation, Close (Informative).

Since:
1.1
See Also:
Constant Field Values

INITIAL_QUOTE_PUNCTUATION

public static final byte INITIAL_QUOTE_PUNCTUATION
Pi = Punctuation, Initial Quote (Informative).

Since:
1.4
See Also:
Constant Field Values

FINAL_QUOTE_PUNCTUATION

public static final byte FINAL_QUOTE_PUNCTUATION
Pf = Punctuation, Final Quote (Informative).

Since:
1.4
See Also:
Constant Field Values

OTHER_PUNCTUATION

public static final byte OTHER_PUNCTUATION
Po = Punctuation, Other (Informative).

Since:
1.1
See Also:
Constant Field Values

MATH_SYMBOL

public static final byte MATH_SYMBOL
Sm = Symbol, Math (Informative).

Since:
1.1
See Also:
Constant Field Values

CURRENCY_SYMBOL

public static final byte CURRENCY_SYMBOL
Sc = Symbol, Currency (Informative).

Since:
1.1
See Also:
Constant Field Values

MODIFIER_SYMBOL

public static final byte MODIFIER_SYMBOL
Sk = Symbol, Modifier (Informative).

Since:
1.1
See Also:
Constant Field Values

OTHER_SYMBOL

public static final byte OTHER_SYMBOL
So = Symbol, Other (Informative).

Since:
1.1
See Also:
Constant Field Values
Constructor Detail

Character

public Character(char value)
Wraps up a character.

Parameters:
value - the character to wrap
Method Detail

charValue

public char charValue()
Returns the character which has been wrapped by this class.

Returns:
the character wrapped

hashCode

public int hashCode()
Returns the numerical value (unsigned) of the wrapped character. Range of returned values: 0x0000-0xFFFF.

Overrides:
hashCode in class Object
Returns:
the value of the wrapped character
See Also:
Object.equals(Object), System.identityHashCode(Object)

equals

public boolean equals(Object o)
Determines if an object is equal to this object. This is only true for another Character object wrapping the same value.

Overrides:
equals in class Object
Parameters:
o - object to compare
Returns:
true if o is a Character with the same value
See Also:
Object.hashCode()

toString

public String toString()
Converts the wrapped character into a String.

Overrides:
toString in class Object
Returns:
a String containing one character -- the wrapped character of this instance
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)

toString

public static String toString(char ch)
Returns a String of length 1 representing the specified character.

Parameters:
ch - the character to convert
Returns:
a String containing the character
Since:
1.4

isLowerCase

public static boolean isLowerCase(char ch)
Determines if a character is a Unicode lowercase letter. For example, 'a' is lowercase.
lowercase = [Ll]

Parameters:
ch - character to test
Returns:
true if ch is a Unicode lowercase letter, else false
See Also:
isUpperCase(char), #isTitleCase(char), toLowerCase(char), #getType(char)

isUpperCase

public static boolean isUpperCase(char ch)
Determines if a character is a Unicode uppercase letter. For example, 'A' is uppercase.
uppercase = [Lu]

Parameters:
ch - character to test
Returns:
true if ch is a Unicode uppercase letter, else false
See Also:
isLowerCase(char), #isTitleCase(char), toUpperCase(char), #getType(char)

isDigit

public static boolean isDigit(char ch)
Determines if a character is a Unicode decimal digit. For example, '0' is a digit.
Unicode decimal digit = [Nd]

Parameters:
ch - character to test
Returns:
true if ch is a Unicode decimal digit, else false
See Also:
digit(char, int), forDigit(int, int), #getType(char)

isLetter

public static boolean isLetter(char ch)
Determines if a character is a Unicode letter. Not all letters have case, so this may return true when isLowerCase and isUpperCase return false.
letter = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]

Parameters:
ch - character to test
Returns:
true if ch is a Unicode letter, else false
See Also:
isDigit(char), #isJavaIdentifierStart(char), #isJavaLetter(char), #isJavaLetterOrDigit(char), isLetterOrDigit(char), isLowerCase(char), #isTitleCase(char), #isUnicodeIdentifierStart(char), isUpperCase(char)

isLetterOrDigit

public static boolean isLetterOrDigit(char ch)
Determines if a character is a Unicode letter or a Unicode digit. This is the combination of isLetter and isDigit.
letter or digit = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nd]

Parameters:
ch - character to test
Returns:
true if ch is a Unicode letter or a Unicode digit, else false
See Also:
isDigit(char), #isJavaIdentifierPart(char), #isJavaLetter(char), #isJavaLetterOrDigit(char), isLetter(char), #isUnicodeIdentifierPart(char)

toLowerCase

public static char toLowerCase(char ch)
Converts a Unicode character into its lowercase equivalent mapping. If a mapping does not exist, then the character passed is returned. Note that isLowerCase(toLowerCase(ch)) does not always return true.

Parameters:
ch - character to convert to lowercase
Returns:
lowercase mapping of ch, or ch if lowercase mapping does not exist
See Also:
isLowerCase(char), isUpperCase(char), #toTitleCase(char), toUpperCase(char)

toUpperCase

public static char toUpperCase(char ch)
Converts a Unicode character into its uppercase equivalent mapping. If a mapping does not exist, then the character passed is returned. Note that isUpperCase(toUpperCase(ch)) does not always return true.

Parameters:
ch - character to convert to uppercase
Returns:
uppercase mapping of ch, or ch if uppercase mapping does not exist
See Also:
isLowerCase(char), isUpperCase(char), toLowerCase(char), #toTitleCase(char)

digit

public static int digit(char ch,
                        int radix)
Converts a character into a digit of the specified radix. If the radix exceeds MIN_RADIX or MAX_RADIX, or if the result of getNumericValue(ch) exceeds the radix, or if ch is not a decimal digit or in the case insensitive set of 'a'-'z', the result is -1.
character argument boundary = [Nd]|U+0041-U+005A|U+0061-U+007A |U+FF21-U+FF3A|U+FF41-U+FF5A

Parameters:
ch - character to convert into a digit
radix - radix in which ch is a digit
Returns:
digit which ch represents in radix, or -1 not a valid digit
See Also:
MIN_RADIX, MAX_RADIX, forDigit(int, int), isDigit(char), #getNumericValue(char)

isSpace

public static boolean isSpace(char ch)
Deprecated. Replaced by isWhitespace(char)

Determines if a character is a ISO-LATIN-1 space. This is only the five characters '\t', '\n', '\f', '\r', and ' '.
Java space = U+0020|U+0009|U+000A|U+000C|U+000D

Parameters:
ch - character to test
Returns:
true if ch is a space, else false
See Also:
isSpaceChar(char), isWhitespace(char)

isSpaceChar

public static boolean isSpaceChar(char ch)
Determines if a character is a Unicode space character. This includes SPACE_SEPARATOR, LINE_SEPARATOR, and PARAGRAPH_SEPARATOR.
Unicode space = [Zs]|[Zp]|[Zl]

Parameters:
ch - character to test
Returns:
true if ch is a Unicode space, else false
Since:
1.1
See Also:
isWhitespace(char)

isWhitespace

public static boolean isWhitespace(char ch)
Determines if a character is Java whitespace. This includes Unicode space characters (SPACE_SEPARATOR, LINE_SEPARATOR, and PARAGRAPH_SEPARATOR) except the non-breaking spaces (' ', '?', and '?'); and these characters: ' ', ' ', ' ', ' ', ' ', '', '', '', and ''.
Java whitespace = ([Zs] not Nb)|[Zl]|[Zp]|U+0009-U+000D|U+001C-U+001F

Parameters:
ch - character to test
Returns:
true if ch is Java whitespace, else false
Since:
1.1
See Also:
isSpaceChar(char)

forDigit

public static char forDigit(int digit,
                            int radix)
Converts a digit into a character which represents that digit in a specified radix. If the radix exceeds MIN_RADIX or MAX_RADIX, or the digit exceeds the radix, then the null character '\0' is returned. Otherwise the return value is in '0'-'9' and 'a'-'z'.
return value boundary = U+0030-U+0039|U+0061-U+007A

Parameters:
digit - digit to be converted into a character
radix - radix of digit
Returns:
character representing digit in radix, or '\0'
See Also:
MIN_RADIX, MAX_RADIX, digit(char, int)

compareTo

public int compareTo(Character anotherCharacter)
Compares another Character to this Character, numerically.

Parameters:
anotherCharacter - Character to compare with this Character
Returns:
a negative integer if this Character is less than anotherCharacter, zero if this Character is equal, and a positive integer if this Character is greater
Throws:
NullPointerException - if anotherCharacter is null
Since:
1.2

compareTo

public int compareTo(Object o)
Compares an object to this Character. Assuming the object is a Character object, this method performs the same comparison as compareTo(Character).

Specified by:
compareTo in interface Comparable
Parameters:
o - object to compare
Returns:
the comparison value
Throws:
ClassCastException - if o is not a Character object
NullPointerException - if o is null
Since:
1.2
See Also:
compareTo(Character)

valueOf

public static Character valueOf(char val)
Returns an Character object wrapping the value. In contrast to the Character constructor, this method will cache some values. It is used by boxing conversion.

Parameters:
val - the value to wrap
Returns:
the Character
Since:
1.5

reverseBytes

public static char reverseBytes(char val)
Reverse the bytes in val.

Since:
1.5