Java Character Methods

About This Index
This page is the Java Character Methods index. Each row links to a full guide with syntax, parameters, return value, three runnable examples, and FAQs. Every example is a complete Java class with a main method and fixed data, so the output shown is the output you get.
Learn what the Character class is on the Character hub. Use this page when you need a specific method such as isLetter(), toUpperCase(), or digit(). The examples compile on Java 8 and later, except codePointOf() (Java 9) and one toString() example that uses the Java 11 code point overload.
A char is one 16-bit UTF-16 unit, which covers U+0000 to U+FFFF. Characters above that, such as the emoji U+1F600, are stored as two char values called a surrogate pair. That is why most methods here come in two versions: one that takes a char and one that takes an int code point. Prefer the int version when your text may contain emoji or rare scripts.
How to Call a Character Method
Most methods are static, so you call them on the class name and pass the character. No import is needed:
char c = 'q';
boolean letter = Character.isLetter(c); // true
char upper = Character.toUpperCase(c); // 'Q'
int seven = Character.digit('7', 10); // 7
int cp = Character.codePointAt("\uD83D\uDE00", 0); // 128512 (U+1F600)
Character boxed = c; // autoboxing
boolean same = boxed.equals('q'); // true (instance method) Java Character Methods Table
All method guides in this Java tutorial series (52 tutorials), grouped by purpose.
Character tests
10 methodsAsk what kind of character you have: a letter, a digit, a space, a control code, a CJK ideograph, or a character that has a mirrored form.
| Method | Description | Tutorial |
|---|---|---|
isLetter() | Check whether a character is a letter in any language. | Try it |
isDigit() | Check whether a character is a decimal digit, such as 0 to 9. | Try it |
isLetterOrDigit() | Check whether a character is a letter or a decimal digit. | Try it |
isAlphabetic() | Check the Unicode Alphabetic property, a wider test than isLetter (Java 7+). | Try it |
isIdeographic() | Check whether a code point is a CJK ideograph, such as a Chinese character (Java 7+). | Try it |
isWhitespace() | Check whether a character is whitespace by Java's rules (spaces, tabs, line breaks). | Try it |
isSpaceChar() | Check for Unicode space, line, and paragraph separators, including the non-breaking space. | Try it |
isISOControl() | Check for ISO control characters: codes 0x00 to 0x1F and 0x7F to 0x9F. | Try it |
isDefined() | Check whether a character is assigned a meaning in Unicode. | Try it |
isMirrored() | Check whether a character's glyph is flipped in right-to-left text, like brackets. | Try it |
Case tests and case conversion
6 methodsCheck whether a character is lowercase, uppercase, or titlecase, and convert one character at a time.
| Method | Description | Tutorial |
|---|---|---|
isLowerCase() | Check whether a character is lowercase, such as a to z. | Try it |
isUpperCase() | Check whether a character is uppercase, such as A to Z. | Try it |
isTitleCase() | Check for titlecase letters, the "capitalised" form of digraphs such as Dz. | Try it |
toLowerCase() | Convert one character to lowercase, using Unicode rules. | Try it |
toUpperCase() | Convert one character to uppercase, using Unicode rules. | Try it |
toTitleCase() | Convert a character to titlecase, the form used at the start of a word. | Try it |
Digits and numeric values
3 methodsTurn a digit character into its number in any base from 2 to 36, turn a number back into a digit character, or read the Unicode numeric value.
| Method | Description | Tutorial |
|---|---|---|
digit() | Get the numeric value of a digit character in a given radix, or -1. | Try it |
forDigit() | Turn a number from 0 to 35 into its digit character for a given radix. | Try it |
getNumericValue() | Get the Unicode numeric value of a character, such as 50 for the Roman numeral L. | Try it |
Unicode code points and surrogates
16 methodsWork with full Unicode code points, including emoji and other characters above U+FFFF that need two char values (a surrogate pair).
| Method | Description | Tutorial |
|---|---|---|
charCount() | Tell whether a code point needs 1 or 2 chars in UTF-16. | Try it |
codePointAt() | Read the full code point at an index of a char sequence or char array. | Try it |
codePointBefore() | Read the full code point that ends just before an index. | Try it |
codePointCount() | Count the code points (real characters) in a range of text. | Try it |
offsetByCodePoints() | Move an index forward or backward by a number of code points. | Try it |
isValidCodePoint() | Check that an int is a valid Unicode code point (0 to 0x10FFFF). | Try it |
isBmpCodePoint() | Check whether a code point fits in a single char (U+0000 to U+FFFF, Java 7+). | Try it |
isSupplementaryCodePoint() | Check whether a code point is above U+FFFF and needs a surrogate pair. | Try it |
isHighSurrogate() | Check whether a char is the first half of a surrogate pair (0xD800 to 0xDBFF). | Try it |
isLowSurrogate() | Check whether a char is the second half of a surrogate pair (0xDC00 to 0xDFFF). | Try it |
isSurrogate() | Check whether a char is either half of a surrogate pair (Java 7+). | Try it |
isSurrogatePair() | Check whether two chars form a valid surrogate pair, in the right order. | Try it |
highSurrogate() | Get the high (leading) surrogate char of a supplementary code point (Java 7+). | Try it |
lowSurrogate() | Get the low (trailing) surrogate char of a supplementary code point (Java 7+). | Try it |
toCodePoint() | Combine a high and a low surrogate into one supplementary code point. | Try it |
toChars() | Convert a code point into its UTF-16 chars: one char, or a surrogate pair. | Try it |
Java and Unicode identifiers
5 methodsCheck which characters may start or continue a Java variable name, or a Unicode identifier, and which ones are ignored inside identifiers.
| Method | Description | Tutorial |
|---|---|---|
isJavaIdentifierStart() | Check whether a character may be the first character of a Java identifier. | Try it |
isJavaIdentifierPart() | Check whether a character may appear after the first character of a Java identifier. | Try it |
isUnicodeIdentifierStart() | Check whether a character may start an identifier under the Unicode rules. | Try it |
isUnicodeIdentifierPart() | Check whether a character may appear inside an identifier under the Unicode rules. | Try it |
isIdentifierIgnorable() | Check whether a character is ignorable inside a Java or Unicode identifier. | Try it |
Type, direction, and name
4 methodsRead the Unicode general category, the bidirectional (left-to-right or right-to-left) class, or the official Unicode name of a character, and look a character up by name.
| Method | Description | Tutorial |
|---|---|---|
getType() | Get the Unicode general category of a character as an int constant. | Try it |
getDirectionality() | Get the bidirectional (left-to-right or right-to-left) class of a character. | Try it |
getName() | Get the official Unicode name of a code point, such as LATIN CAPITAL LETTER A (Java 7+). | Try it |
codePointOf() | Look up a code point by its Unicode name, such as "GRINNING FACE" (Java 9+). | Try it |
Compare, equality, and hash codes
4 methodsOrder two characters, check whether two Character objects hold the same value, and get a hash code.
| Method | Description | Tutorial |
|---|---|---|
compare() | Compare two primitive char values numerically (Java 7+). | Try it |
compareTo() | Compare two Character objects by their numeric char values. | Try it |
equals() | Check whether an object is a Character holding the same char value. | Try it |
hashCode() | Get the hash code of a char: simply its numeric value. | Try it |
Boxing, unboxing, and conversion
4 methodsWrap a char in a Character object, unwrap it again, turn it into a String, or swap its two bytes.
| Method | Description | Tutorial |
|---|---|---|
valueOf() | Wrap a char in a Character object, reusing cached objects for ASCII. | Try it |
charValue() | Get the primitive char stored inside a Character object. | Try it |
toString() | Turn a char, a Character, or (Java 11+) a code point into a String. | Try it |
reverseBytes() | Swap the two bytes of a char, converting between big-endian and little-endian. | Try it |
Frequently Asked Questions
Start with isLetter()
The most common character test: is this char a letter?
12 people found this page helpful
