Module java.base
Package java.lang

Class Character

java.lang.Object
java.lang.Character
All Implemented Interfaces:
Serializable,Comparable<Character>,Constable

public final classCharacterextendsObjectimplementsSerializable,Comparable<Character>,Constable
TheCharacter class wraps a value of the primitive typechar in an object. An object of classCharacter contains a single field whose type ischar.

In addition, this class provides a large number of static methods for determining a character's category (lowercase letter, digit, etc.) and for converting characters from uppercase to lowercase and vice versa.

Unicode Conformance

The fields and methods of classCharacter are defined in terms of character information from the Unicode Standard, specifically theUnicodeData file that is part of the Unicode Character Database. This file specifies properties including name and category for every assigned Unicode code point or character range. The file is available from the Unicode Consortium athttp://www.unicode.org.

Character information is based on the Unicode Standard, version 15.1.

The Java platform has supported different versions of the Unicode Standard over time. Upgrades to newer versions of the Unicode Standard occurred in the following Java releases, each indicating the new version:

Shows Java releases and supported Unicode versions
Java releaseUnicode version
Java SE 22Unicode 15.1
Java SE 20Unicode 15.0
Java SE 19Unicode 14.0
Java SE 15Unicode 13.0
Java SE 13Unicode 12.1
Java SE 12Unicode 11.0
Java SE 11Unicode 10.0
Java SE 9Unicode 8.0
Java SE 8Unicode 6.2
Java SE 7Unicode 6.0
Java SE 5.0Unicode 4.0
Java SE 1.4Unicode 3.0
JDK 1.1Unicode 2.0
JDK 1.0.2Unicode 1.1.5
Variations from these base Unicode versions, such as recognized appendixes, are documented elsewhere.

Unicode Character Representations

Thechar data type (and therefore the value that aCharacter object encapsulates) are based on the original Unicode specification, which defined characters as fixed-width 16-bit entities. The Unicode Standard has since been changed to allow for characters whose representation requires more than 16 bits. The range of legalcode points is now U+0000 to U+10FFFF, known asUnicode scalar value. (Refer to the definition of the U+n notation in the Unicode Standard.)

The set of characters from U+0000 to U+FFFF is sometimes referred to as theBasic Multilingual Plane (BMP).Characters whose code points are greater than U+FFFF are calledsupplementary characters. The Java platform uses the UTF-16 representation inchar arrays and in theString andStringBuffer classes. In this representation, supplementary characters are represented as a pair ofchar values, the first from thehigh-surrogates range, (\uD800-\uDBFF), the second from thelow-surrogates range (\uDC00-\uDFFF).

Achar value, therefore, represents Basic Multilingual Plane (BMP) code points, including the surrogate code points, or code units of the UTF-16 encoding. Anint value represents all Unicode code points, including supplementary code points. The lower (least significant) 21 bits ofint are used to represent Unicode code points and the upper (most significant) 11 bits must be zero. Unless otherwise specified, the behavior with respect to supplementary characters and surrogatechar values is as follows:

  • The methods that only accept achar value cannot support supplementary characters. They treatchar values from the surrogate ranges as undefined characters. For example,Character.isLetter('\uD840') returnsfalse, even though this specific value if followed by any low-surrogate value in a string would represent a letter.
  • The methods that accept anint value support all Unicode characters, including supplementary characters. For example,Character.isLetter(0x2F81A) returnstrue because the code point value represents a letter (a CJK ideograph).

In the Java SE API documentation,Unicode code point is used for character values in the range between U+0000 and U+10FFFF, andUnicode code unit is used for 16-bitchar values that are code units of theUTF-16 encoding. For more information on Unicode terminology, refer to theUnicode Glossary.

This is avalue-based class; programmers should treat instances that areequal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail.

Since:
1.0
External Specifications
See Also: