In Java, Character.isIdeographic(codePoint) returns true when the code point has the Unicode Ideographic property. These are the CJK ideographs used in Chinese, as kanji in Japanese, and as hanja in Korean, such as U+4E2D ("middle") and U+6587 ("writing").
Many characters in East Asian text are not ideographs. Japanese Hiragana and Katakana and Korean Hangul syllables are letters, so isLetter() returns true for them, but isIdeographic returns false.
A static method of java.lang.Character (Java 7+): call it on the class, as in Character.isIdeographic(...); you do not need a Character object. No import is needed, because java.lang is always available.
Unicode version.
The answer comes from the Unicode Character Database built into your JDK, and each Java release follows a specific Unicode version (Java 8, for example, uses Unicode 6.2). The characters used on this page have had the same properties for many Unicode versions, so the examples print the same result on any current JDK.
Syntax
Only an int overload exists; pass a code point (a char is widened).
Java
Character.isIdeographic(0x4E2D); // true (CJK "middle")
Character.isIdeographic('A'); // false
Character.isIdeographic(0x3042); // false (Hiragana A is a letter, not an ideograph)
Character.isIdeographic(0x20000); // true (CJK Extension B, two chars in a String)
Call
What it does
Character.isIdeographic(cp)
Test one code point.
Character.isIdeographic(s.codePointAt(i))
Test the character at index i, including characters above U+FFFF.
Character.isIdeographic(s.charAt(i))
Works for the common ideographs below U+FFFF only.
Added in Java 7 with only an int parameter. Many ideographs live above U+FFFF (the CJK extension blocks), so read characters with codePointAt rather than charAt.
Library declarations
Java
// java.lang.Character (since Java 7)
public static boolean isIdeographic(int codePoint)
Parameters
Parameter
Description
codePoint (int)
The Unicode code point to test.
Return Value
Return Value
Description
true
The code point is an ideograph, as defined by the Unicode Ideographic property.
false
Anything else, including Hiragana, Katakana, Hangul, Latin letters, and surrogate halves.
All six are letters. Latin A, the two Han characters, Hiragana A (12354), Katakana A (12450), and the Hangul syllable GA (44032) all pass isLetter.
Only Han is ideographic. U+4E2D and U+6587 have the Ideographic property; the kana and Hangul are phonetic scripts, so they print false.
Decimal codes. The array uses hex literals such as 0x4E2D, while println prints the same values in decimal, such as 20013.
Example 2 — Count the Kanji in a Japanese Phrase
The phrase "nihongo desu" mixes three kanji with two Hiragana characters.
Java
public class CharacterIsIdeographicCount {
public static void main(String[] args) {
String phrase = "\u65E5\u672C\u8A9E\u3067\u3059";
int letters = 0;
int ideographs = 0;
for (int i = 0; i < phrase.length(); i++) {
int cp = phrase.codePointAt(i);
if (Character.isLetter(cp)) letters++;
if (Character.isIdeographic(cp)) ideographs++;
}
System.out.println("letters=" + letters + " ideographs=" + ideographs);
}
}
Output
letters=5 ideographs=3
How It Works
Five BMP characters. The kanji U+65E5, U+672C, and U+8A9E are followed by the Hiragana U+3067 and U+3059; each fits in one char, so stepping i by 1 is safe here.
Two independent counters. Each code point is checked by both tests, so one character can add to both totals.
The kana count as letters only. All five are letters, but only the three kanji are ideographs.
Example 3 — An Ideograph Stored as a Surrogate Pair
U+20000 is the first character of CJK Unified Ideographs Extension B. Test its first char and then its real code point.
Java
public class CharacterIsIdeographicExtB {
public static void main(String[] args) {
String rare = "\uD840\uDC00";
int cp = rare.codePointAt(0);
System.out.println("length=" + rare.length() + " codePoint=0x" + Integer.toHexString(cp));
System.out.println("first char only: " + Character.isIdeographic(rare.charAt(0)));
System.out.println("whole code point: " + Character.isIdeographic(cp));
}
}
Output
length=2 codePoint=0x20000
first char only: false
whole code point: true
How It Works
Built from a surrogate pair.\uD840 followed by \uDC00 is how UTF-16 stores U+20000, so the String has length 2.
The char is widened, not combined.charAt(0) gives 0xD840, which becomes the int 55360, a surrogate code point with no Ideographic property.
The real character.codePointAt(0) returns 0x20000, and isIdeographic recognises it as a Han ideograph.
Frequently Asked Questions
Java 7. It takes an int code point; there is no char overload, but a char argument is widened automatically.
No. They are phonetic letters, so isLetter returns true and isIdeographic returns false.
No. Hangul is an alphabet. Korean hanja, which are Han characters, are ideographic.
Loop over code points and test isIdeographic, or check Character.UnicodeScript.of(cp) == Character.UnicodeScript.HAN for a script-based test. Both need Java 7 or newer.
Tens of thousands of ideographs are above U+FFFF and stored as two chars. charAt would hand the method one surrogate half, which always returns false.