public final class Character extends Object implements Serializable, 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.0.0.
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 . |
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. |
static int |
compare(char x,
char y)
Compares two
char values numerically. |
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)
Converts the character argument to lowercase using case mapping information from the UnicodeData
file.
|
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 using case mapping information from the UnicodeData
file.
|
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, the 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 static int compare(char x, char y)
char
values numerically. The value returned is identical to what would be
returned by:
Character.valueOf(x).compareTo(Character.valueOf(y))
x
- the first char
to comparey
- the second char
to compare0
if x == y
; a value less than 0
if x < y
; and
a value greater than 0
if x > y
public static int digit(char ch, int radix)
ch
- the character to be converted.radix
- the radix.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 static boolean isDigit(char ch)
Some Unicode character ranges that contain digits:
'\u0030'
through '\u0039'
, ISO-LATIN-1 digits ('0'
through
'9'
)
'\u0660'
through '\u0669'
, Arabic-Indic digits
'\u06F0'
through '\u06F9'
, Extended Arabic-Indic digits
'\u0966'
through '\u096F'
, Devanagari digits
'\uFF10'
through '\uFF19'
, 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 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)
A character is lowercase if its general category type, provided by Character.getType(ch)
,
is LOWERCASE_LETTER
, or it has contributory property Other_Lowercase as defined by the
Unicode Standard.
The following are examples of lowercase characters:
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)
,
toLowerCase(char)
public static boolean isSpaceChar(char ch)
SPACE_SEPARATOR
LINE_SEPARATOR
PARAGRAPH_SEPARATOR
ch
- the character to be tested.true
if the character is a space character; false
otherwise.isWhitespace(char)
public static boolean isUpperCase(char ch)
A character is uppercase if its general category type, provided by Character.getType(ch)
,
is UPPERCASE_LETTER
. or it has contributory property Other_Uppercase as defined by the
Unicode Standard.
The following are examples of uppercase characters:
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)
,
toUpperCase(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 Character.isLowerCase(Character.toLowerCase(ch))
does not always return
true
for some ranges of characters, particularly those that are symbols or ideographs.
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 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 Character.isUpperCase(Character.toUpperCase(ch))
does not always return
true
for some ranges of characters, particularly those that are symbols or ideographs.
In general, String.toUpperCase()
should be used to map characters to uppercase.
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.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.
This method will always cache values in the range '\u0000'
to '\u007F'
,
inclusive, and may cache other values outside of this range.c
- a char value.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 boolean equals(@Nullable 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 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 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.