Team LiB
Previous Section Next Section

Characterjava.lang

Java 1.0serializable comparable

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; for example, use 16 for hexadecimal). It works with any Unicode digit character, and also (for sufficiently large radix values) the ASCII letters a-z and A-Z. forDigit( ) returns the ASCII character that corresponds to the specified value (0-35) for the specified radix. getNumericValue( ) is similar, but also works with any Unicode character including those, such as Roman numerals, that represent numbers but are not decimal digits. Finally, the static toString( ) method returns a String of length 1 that contains the specified char value.

Java 5.0 introduces many new methods to this class to accommodate Unicode supplementary characters that use 21 bits and do not fit in a single char value. The two representations for these supplementary characters are as an int codepoint in the range 0 through 0x10ffff, or as a sequence of two char values known as a "surrogate pair." The first char of such a pair should fall in the "high surrogate" range and the second char should fall in the "low surrogate" range. toChars( ) converts an int codepoint into one or two char values. toCodePoint( ) , codePointAt( ), and codePointBefore( ) convert one or two char values into the corresponding int value. codePointCount( ) returns the number of characters in a char array or CharSequence, counting surrogate pairs as a single supplementary character. offsetByCodePoints( ) tells you how many char indexes to advance in a run of text if you want to skip over the specified number of code points. Finally, the various character type testing and case conversion methods such as isWhitespace( ) and toUpperCase( ) are available in new versions that take an int codepoint argument instead of a single char argument.

Figure 10-9. java.lang.Character


public final class Character implements Serializable, Comparable<Character> {
// Public Constructors
     public Character(char value);  
// Public Constants
1.1  public static final byte COMBINING_SPACING_MARK;                =8
1.1  public static final byte CONNECTOR_PUNCTUATION;                 =23
1.1  public static final byte CONTROL; =15
1.1  public static final byte CURRENCY_SYMBOL;                       =26
1.1  public static final byte DASH_PUNCTUATION;                      =20
1.1  public static final byte DECIMAL_DIGIT_NUMBER;                  =9
1.4  public static final byte DIRECTIONALITY_ARABIC_NUMBER;          =6
1.4  public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL;       =9
1.4  public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR;     =7
1.4  public static final byte DIRECTIONALITY_EUROPEAN_NUMBER;        =3
1.4  public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR;     =4
1.4  public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR;     =5
1.4  public static final byte DIRECTIONALITY_LEFT_TO_RIGHT;          =0
1.4  public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING;     =14
1.4  public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE;     =15
1.4  public static final byte DIRECTIONALITY_NONSPACING_MARK;        =8
1.4  public static final byte DIRECTIONALITY_OTHER_NEUTRALS;         =13
1.4  public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR;     =10
1.4  public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT;     =18
1.4  public static final byte DIRECTIONALITY_RIGHT_TO_LEFT;          =1
1.4  public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;     =2
1.4  public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING;     =16
1.4  public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE;     =17
1.4  public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR;      =11
1.4  public static final byte DIRECTIONALITY_UNDEFINED;              =-1
1.4  public static final byte DIRECTIONALITY_WHITESPACE;             =12
1.1  public static final byte ENCLOSING_MARK;                        =7
1.1  public static final byte END_PUNCTUATION;                       =22
1.4  public static final byte FINAL_QUOTE_PUNCTUATION;               =30
1.1  public static final byte FORMAT;  =16
1.4  public static final byte INITIAL_QUOTE_PUNCTUATION;             =29
1.1  public static final byte LETTER_NUMBER;                         =10
1.1  public static final byte LINE_SEPARATOR;                        =13
1.1  public static final byte LOWERCASE_LETTER;                      =2
1.1  public static final byte MATH_SYMBOL;                           =25
5.0  public static final int MAX_CODE_POINT;                         =1114111
5.0  public static final char MAX_HIGH_SURROGATE;                    = \uDBFF 
5.0  public static final char MAX_LOW_SURROGATE;                     = \uDFFF 
     public static final int MAX_RADIX;    =36
5.0  public static final char MAX_SURROGATE;                         = \uDFFF 
     public static final char MAX_VALUE;   = \uFFFF 
5.0  public static final int MIN_CODE_POINT;                         =0
5.0  public static final char MIN_HIGH_SURROGATE;                    = \uD800 
5.0  public static final char MIN_LOW_SURROGATE;                     = \uDC00 
     public static final int MIN_RADIX;    =2
5.0  public static final int MIN_SUPPLEMENTARY_CODE_POINT;           =65536
5.0  public static final char MIN_SURROGATE;                         = \uD800 
     public static final char MIN_VALUE;   = \0 
1.1  public static final byte MODIFIER_LETTER;                       =4
1.1  public static final byte MODIFIER_SYMBOL;                       =27
1.1  public static final byte NON_SPACING_MARK;                      =6
1.1  public static final byte OTHER_LETTER;                          =5
1.1  public static final byte OTHER_NUMBER;                          =11
1.1  public static final byte OTHER_PUNCTUATION;                     =24
1.1  public static final byte OTHER_SYMBOL;                          =28
1.1  public static final byte PARAGRAPH_SEPARATOR;                   =14
1.1  public static final byte PRIVATE_USE;                           =18
5.0  public static final int SIZE;     =16
1.1  public static final byte SPACE_SEPARATOR;                       =12
1.1  public static final byte START_PUNCTUATION;                     =21
1.1  public static final byte SURROGATE;                             =19
1.1  public static final byte TITLECASE_LETTER;                      =3
1.1  public static final Class<Character> TYPE;  
1.1  public static final byte UNASSIGNED;                            =0
1.1  public static final byte UPPERCASE_LETTER;                      =1
// Nested Types
1.2  public static class Subset; 
1.2  public static final class UnicodeBlock extends Character.Subset; 
// Public Class Methods
5.0  public static int charCount(int codePoint);  
5.0  public static int codePointAt(char[ ] a, int index);  
5.0  public static int codePointAt(CharSequence seq, int index);  
5.0  public static int codePointAt(char[ ] a, int index, int limit);  
5.0  public static int codePointBefore(CharSequence seq, int index);  
5.0  public static int codePointBefore(char[ ] a, int index);  
5.0  public static int codePointBefore(char[ ] a, int index, int start);  
5.0  public static int codePointCount(char[ ] a, int offset, int count);  
5.0  public static int codePointCount(CharSequence seq, int beginIndex, int endIndex);  
5.0  public static int digit(int codePoint, int radix);  
     public static int digit(char ch, int radix);  
     public static char forDigit(int digit, int radix);  
1.4  public static byte getDirectionality(char ch);  
5.0  public static byte getDirectionality(int codePoint);  
1.1  public static int getNumericValue(char ch);  
5.0  public static int getNumericValue(int codePoint);  
1.1  public static int getType(char ch);  
5.0  public static int getType(int codePoint);  
5.0  public static boolean isDefined(int codePoint);  
     public static boolean isDefined(char ch);  
5.0  public static boolean isDigit(int codePoint);  
     public static boolean isDigit(char ch);  
5.0  public static boolean isHighSurrogate(char ch);  
5.0  public static boolean isIdentifierIgnorable(int codePoint);  
1.1  public static boolean isIdentifierIgnorable(char ch);  
1.1  public static boolean isISOControl(char ch);  
5.0  public static boolean isISOControl(int codePoint);  
1.1  public static boolean isJavaIdentifierPart(char ch);  
5.0  public static boolean isJavaIdentifierPart(int codePoint);  
1.1  public static boolean isJavaIdentifierStart(char ch);  
5.0  public static boolean isJavaIdentifierStart(int codePoint);  
     public static boolean isLetter(char ch);  
5.0  public static boolean isLetter(int codePoint);  
     public static boolean isLetterOrDigit(char ch);  
5.0  public static boolean isLetterOrDigit(int codePoint);  
5.0  public static boolean isLowerCase(int codePoint);  
     public static boolean isLowerCase(char ch);  
5.0  public static boolean isLowSurrogate(char ch);  
5.0  public static boolean isMirrored(int codePoint);  
1.4  public static boolean isMirrored(char ch);  
5.0  public static boolean isSpaceChar(int codePoint);  
1.1  public static boolean isSpaceChar(char ch);  
5.0  public static boolean isSupplementaryCodePoint(int codePoint);  
5.0  public static boolean isSurrogatePair(char high, char low);  
     public static boolean isTitleCase(char ch);  
5.0  public static boolean isTitleCase(int codePoint);  
1.1  public static boolean isUnicodeIdentifierPart(char ch);  
5.0  public static boolean isUnicodeIdentifierPart(int codePoint);  
5.0  public static boolean isUnicodeIdentifierStart(int codePoint);  
1.1  public static boolean isUnicodeIdentifierStart(char ch);  
     public static boolean isUpperCase(char ch);  
5.0  public static boolean isUpperCase(int codePoint);  
5.0  public static boolean isValidCodePoint(int codePoint);  
5.0  public static boolean isWhitespace(int codePoint);  
1.1  public static boolean isWhitespace(char ch);  
5.0  public static int offsetByCodePoints(CharSequence seq, int index, 
      int codePointOffset);  
5.0  public static int offsetByCodePoints(char[ ] a, int start, int count, 
      int index, int codePointOffset);  
5.0  public static char reverseBytes(char ch);  
5.0  public static char[ ] toChars(int codePoint);  
5.0  public static int toChars(int codePoint, char[ ] dst, int dstIndex);  
5.0  public static int toCodePoint(char high, char low);  
     public static char toLowerCase(char ch);  
5.0  public static int toLowerCase(int codePoint);  
1.4  public static String toString(char c);  
     public static char toTitleCase(char ch);  
5.0  public static int toTitleCase(int codePoint);  
     public static char toUpperCase(char ch);  
5.0  public static int toUpperCase(int codePoint);  
5.0  public static Character valueOf(char c);  
// Public Instance Methods
     public char charValue( );  
// Methods Implementing Comparable
1.2  public int compareTo(Character anotherCharacter);  
// Public Methods Overriding Object
     public boolean equals(Object obj);  
     public int hashCode( );  
     public String toString( );  
// Deprecated Public Methods
#    public static boolean isJavaLetter(char ch);  
#    public static boolean isJavaLetterOrDigit(char ch);  
#    public static boolean isSpace(char ch);  
}

    Team LiB
    Previous Section Next Section