public final class

Character

extends Object
java.lang.Object
   ↳ java.lang.Character

Class Overview

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.

Summary

Constants
int MAX_CODE_POINT The maximum value of a Unicode code point.
char MAX_HIGH_SURROGATE The maximum value of a Unicode high-surrogate code unit in the UTF-16 encoding.
char MAX_LOW_SURROGATE The maximum value of a Unicode low-surrogate code unit in the UTF-16 encoding.
int MAX_RADIX The maximum radix available for conversion to and from Strings.
char MAX_SURROGATE The maximum value of a Unicode surrogate code unit in the UTF-16 encoding.
char MAX_VALUE The constant value of this field is the largest value of type char.
int MIN_CODE_POINT The minimum value of a Unicode code point.
char MIN_HIGH_SURROGATE The minimum value of a Unicode high-surrogate code unit in the UTF-16 encoding.
char MIN_LOW_SURROGATE The minimum value of a Unicode low-surrogate code unit in the UTF-16 encoding.
int MIN_RADIX The minimum radix available for conversion to and from Strings.
int MIN_SUPPLEMENTARY_CODE_POINT The minimum value of a supplementary code point.
char MIN_SURROGATE The minimum value of a Unicode surrogate code unit in the UTF-16 encoding.
char MIN_VALUE The constant value of this field is the smallest value of type char.
Public Constructors
Character(char value)
Constructs a Character object and initializes it so that it represents the primitive value argument.
Public Methods
char charValue()
Returns the value of this Character object.
static int codePointAt(char[] a, int index)
Returns the code point at the given index of the char array.
static int codePointAt(char[] a, int index, int limit)
Returns the code point at the given index of the char array, where only array elements with index less than limit can be used.
static int codePointAt(CharSequence seq, int index)
Returns the code point at the given index of the CharSequence.
static int codePointBefore(char[] a, int index)
Returns the code point preceding the given index of the char array.
static int codePointBefore(CharSequence seq, int index)
Returns the code point preceding the given index of the CharSequence.
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.
int hashCode()
Returns a hash code for this Character.
static boolean isDigit(char ch)
Determines if the specified character is a digit.
static boolean isHighSurrogate(char ch)
Determines if the given char value is a high-surrogate code unit (also known as leading-surrogate code unit).
static boolean isLowSurrogate(char ch)
Determines if the given char value is a low-surrogate code unit (also known as trailing-surrogate code unit).
static boolean isLowerCase(char ch)
Determines if the specified character is a lowercase character.
static boolean isUpperCase(char ch)
Determines if the specified character is an uppercase character.
static boolean isValidCodePoint(int codePoint)
Determines whether the specified code point is a valid Unicode code point value in the range of 0x0000 to 0x10FFFF inclusive.
static int toCodePoint(char high, char low)
Converts the specified surrogate pair to its supplementary code point value.
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 toUpperCase(char ch)
Converts the character argument to uppercase; if the character has no lowercase equivalent, the character itself is returned.
static Character valueOf(char c)
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int MAX_CODE_POINT

The maximum value of a Unicode code point.

Constant Value: 1114111 (0x0010ffff)

public static final char MAX_HIGH_SURROGATE

The maximum value of a Unicode high-surrogate code unit in the UTF-16 encoding. A high-surrogate is also known as a leading-surrogate.

Constant Value: 56319 (0x0000dbff)

public static final char MAX_LOW_SURROGATE

The maximum value of a Unicode low-surrogate code unit in the UTF-16 encoding. A low-surrogate is also known as a trailing-surrogate.

Constant Value: 57343 (0x0000dfff)

public static final int MAX_RADIX

The maximum radix available for conversion to and from Strings.

Constant Value: 36 (0x00000024)

public static final char MAX_SURROGATE

The maximum value of a Unicode surrogate code unit in the UTF-16 encoding.

Constant Value: 57343 (0x0000dfff)

public static final char MAX_VALUE

The constant value of this field is the largest value of type char.

Constant Value: 65535 (0x0000ffff)

public static final int MIN_CODE_POINT

The minimum value of a Unicode code point.

Constant Value: 0 (0x00000000)

public static final char MIN_HIGH_SURROGATE

The minimum value of a Unicode high-surrogate code unit in the UTF-16 encoding. A high-surrogate is also known as a leading-surrogate.

Constant Value: 55296 (0x0000d800)

public static final char MIN_LOW_SURROGATE

The minimum value of a Unicode low-surrogate code unit in the UTF-16 encoding. A low-surrogate is also known as a trailing-surrogate.

Constant Value: 56320 (0x0000dc00)

public static final int MIN_RADIX

The minimum radix available for conversion to and from Strings.

Constant Value: 2 (0x00000002)

public static final int MIN_SUPPLEMENTARY_CODE_POINT

The minimum value of a supplementary code point.

Constant Value: 65536 (0x00010000)

public static final char MIN_SURROGATE

The minimum value of a Unicode surrogate code unit in the UTF-16 encoding.

Constant Value: 55296 (0x0000d800)

public static final char MIN_VALUE

The constant value of this field is the smallest value of type char.

Constant Value: 0 (0x00000000)

Public Constructors

public Character (char value)

Constructs a Character object and initializes it so that it represents the primitive value argument.

Parameters
value value for the new Character object.

Public Methods

public char charValue ()

Returns the value of this Character object.

Returns
  • the primitive char value represented by this object.

public static int codePointAt (char[] a, int index)

Returns the code point at the given index of the char array. If the char value at the given index in the char array is in the high-surrogate range, the following index is less than the length of the char array, and the char value at the following index is in the low-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at the given index is returned.

Parameters
a the char array
index the index to the char values (Unicode code units) in the char array to be converted
Returns
  • the Unicode code point at the given index
Throws
NullPointerException if a is null.
IndexOutOfBoundsException if the value index is negative or not less than the length of the char array.

public static int codePointAt (char[] a, int index, int limit)

Returns the code point at the given index of the char array, where only array elements with index less than limit can be used. If the char value at the given index in the char array is in the high-surrogate range, the following index is less than the limit, and the char value at the following index is in the low-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at the given index is returned.

Parameters
a the char array
index the index to the char values (Unicode code units) in the char array to be converted
limit the index after the last array element that can be used in the char array
Returns
  • the Unicode code point at the given index
Throws
NullPointerException if a is null.
IndexOutOfBoundsException if the index argument is negative or not less than the limit argument, or if the limit argument is negative or greater than the length of the char array.

public static int codePointAt (CharSequence seq, int index)

Returns the code point at the given index of the CharSequence. If the char value at the given index in the CharSequence is in the high-surrogate range, the following index is less than the length of the CharSequence, and the char value at the following index is in the low-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at the given index is returned.

Parameters
seq a sequence of char values (Unicode code units)
index the index to the char values (Unicode code units) in seq to be converted
Returns
  • the Unicode code point at the given index
Throws
NullPointerException if seq is null.
IndexOutOfBoundsException if the value index is negative or not less than seq.length().

public static int codePointBefore (char[] a, int index)

Returns the code point preceding the given index of the char array. If the char value at (index - 1) in the char array is in the low-surrogate range, (index - 2) is not negative, and the char value at (index - 2) in the char array is in the high-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at (index - 1) is returned.

Parameters
a the char array
index the index following the code point that should be returned
Returns
  • the Unicode code point value before the given index.
Throws
NullPointerException if a is null.
IndexOutOfBoundsException if the index argument is less than 1 or greater than the length of the char array

public static int codePointBefore (CharSequence seq, int index)

Returns the code point preceding the given index of the CharSequence. If the char value at (index - 1) in the CharSequence is in the low-surrogate range, (index - 2) is not negative, and the char value at (index - 2) in the CharSequence is in the high-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at (index - 1) is returned.

Parameters
seq the CharSequence instance
index the index following the code point that should be returned
Returns
  • the Unicode code point value before the given index.
Throws
NullPointerException if seq is null.
IndexOutOfBoundsException if the index argument is less than 1 or greater than seq.length().

public static int digit (char ch, int radix)

Returns the numeric value of the character ch in the specified radix.

Parameters
ch the character to be converted.
radix the radix.
Returns
  • the numeric value represented by the character in the specified radix.
See Also

public boolean equals (Object obj)

Compares this object against the specified object. The result is true if and only if the argument is not null and is a Character object that represents the same char value as this object.

Parameters
obj the object to compare with.
Returns
  • true if the objects are the same; false otherwise.

public int hashCode ()

Returns a hash code for this Character.

Returns
  • a hash code value for this object.

public static boolean isDigit (char ch)

Determines if the specified character is a digit.

Parameters
ch the character to be tested.
Returns
  • true if the character is a digit; false otherwise.

public static boolean isHighSurrogate (char ch)

Determines if the given char value is a high-surrogate code unit (also known as leading-surrogate code unit). Such values do not represent characters by themselves, but are used in the representation of supplementary characters in the UTF-16 encoding.

This method returns true if and only if

 ch >= '\uD800' && ch <= '\uDBFF'
 
is true.

Parameters
ch the char value to be tested.
Returns
  • true if the char value is between '\uD800' and '\uDBFF' inclusive; false otherwise.
See Also

public static boolean isLowSurrogate (char ch)

Determines if the given char value is a low-surrogate code unit (also known as trailing-surrogate code unit). Such values do not represent characters by themselves, but are used in the representation of supplementary characters in the UTF-16 encoding.

This method returns true if and only if

 ch >= '\uDC00' && ch <= '\uDFFF'
 
is true.

Parameters
ch the char value to be tested.
Returns
  • true if the char value is between '\uDC00' and '\uDFFF' inclusive; false otherwise.

public static boolean isLowerCase (char ch)

Determines if the specified character is a lowercase character.

Parameters
ch the character to be tested.
Returns
  • true if the character is lowercase; false otherwise.

public static boolean isUpperCase (char ch)

Determines if the specified character is an uppercase character.

Parameters
ch the character to be tested.
Returns
  • true if the character is uppercase; false otherwise.

public static boolean isValidCodePoint (int codePoint)

Determines whether the specified code point is a valid Unicode code point value in the range of 0x0000 to 0x10FFFF inclusive. This method is equivalent to the expression:

 codePoint >= 0x0000 && codePoint <= 0x10FFFF
 

Parameters
codePoint the Unicode code point to be tested
Returns
  • true if the specified code point value is a valid code point value; false otherwise.

public static int toCodePoint (char high, char low)

Converts the specified surrogate pair to its supplementary code point value. This method does not validate the specified surrogate pair.

Parameters
high the high-surrogate code unit
low the low-surrogate code unit
Returns
  • the supplementary code point composed from the specified surrogate pair.

public 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.

Parameters
ch the character to be converted.
Returns
  • the lowercase equivalent of the character, if any; otherwise the character itself.

public String toString ()

Returns a String object representing this character's value. Converts this 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.

Returns
  • a string representation of this object.

public static char toUpperCase (char ch)

Converts the character argument to uppercase; if the character has no lowercase equivalent, the character itself is returned.

Parameters
ch the character to be converted.
Returns
  • the uppercase equivalent of the character, if any; otherwise the character itself.

public static Character valueOf (char c)