Java Character getType() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.lang.Character

Definition

In Java, Character.getType(ch) returns the character's Unicode general category: the basic kind of character it is. The result is an int that matches one of the constants in Character, such as UPPERCASE_LETTER (1), DECIMAL_DIGIT_NUMBER (9), SPACE_SEPARATOR (12), or MATH_SYMBOL (25).

Many other methods are built on it: isUpperCase() and isDigit(), for example, are essentially "is the type this category?". Code points with no character assigned return UNASSIGNED (0).

A static method of java.lang.Character (Java 1.1+): call it on the class, as in Character.getType(...); you do not need a Character object. No import is needed, because java.lang is always available. The int codePoint overload was added in Java 5.

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

Pass a char or an int code point; compare the result with the constants.

Java
Character.getType('A') == Character.UPPERCASE_LETTER       // true (1)
Character.getType('7') == Character.DECIMAL_DIGIT_NUMBER   // true (9)
Character.getType(' ') == Character.SPACE_SEPARATOR        // true (12)
Character.getType('+') == Character.MATH_SYMBOL            // true (25)
Character.getType(0x10FFFF) == Character.UNASSIGNED        // true (0)
CallWhat it does
Character.getType(c) == Character.OTHER_PUNCTUATIONTest for one category.
switch (Character.getType(c)) { case Character.UPPERCASE_LETTER: ... }Branch on several categories.
Character.getType(s.codePointAt(i))Category of a character above U+FFFF.

Two overloads: getType(char ch) since Java 1.1 and getType(int codePoint) since Java 5. The constants are byte values, but the method returns int.

Library declarations
Java
// java.lang.Character
public static int getType(char ch)          // Java 1.1
public static int getType(int codePoint)    // Java 5

public static final byte UNASSIGNED = 0, UPPERCASE_LETTER = 1, LOWERCASE_LETTER = 2;
public static final byte DECIMAL_DIGIT_NUMBER = 9, SPACE_SEPARATOR = 12, MATH_SYMBOL = 25;

Parameters

ParameterDescription
ch (char)The character to classify.
codePoint (int)A Unicode code point.

Return Value

Return ValueDescription
intOne of the 30 category constants: 0 to 30, with 17 unused.

Compare with Similar Methods

Methods built on the same data:

MethodHow it differs
isLetter(ch)Any of the five letter categories.
isDefined(ch)getType(ch) != UNASSIGNED.
getDirectionality(ch)A different property: bidirectional class.

Java Examples

Example 1 — The General Category of Eight ASCII Characters

Classify letters, a digit, a space, and four kinds of symbols and punctuation, printing the number and constant name.

Java
public class CharacterGetTypeTable {
    static String name(int type) {
        switch (type) {
            case Character.UPPERCASE_LETTER: return "UPPERCASE_LETTER";
            case Character.LOWERCASE_LETTER: return "LOWERCASE_LETTER";
            case Character.DECIMAL_DIGIT_NUMBER: return "DECIMAL_DIGIT_NUMBER";
            case Character.SPACE_SEPARATOR: return "SPACE_SEPARATOR";
            case Character.MATH_SYMBOL: return "MATH_SYMBOL";
            case Character.CURRENCY_SYMBOL: return "CURRENCY_SYMBOL";
            case Character.DASH_PUNCTUATION: return "DASH_PUNCTUATION";
            case Character.START_PUNCTUATION: return "START_PUNCTUATION";
            default: return "other";
        }
    }

    public static void main(String[] args) {
        char[] chars = {'A', 'a', '7', ' ', '+', '$', '-', '('};
        for (char c : chars) {
            int t = Character.getType(c);
            System.out.println("'" + c + "' " + t + " " + name(t));
        }
    }
}

How It Works

  1. Constants as case labels. The category constants are compile-time constants, so they can be used directly in a switch.
  2. Symbols are split up. '+' is a math symbol and '$' a currency symbol: two different categories.
  3. Punctuation is split too. The hyphen-minus is dash punctuation, while '(' is start punctuation (an opening bracket).

Example 2 — Count Each Kind of Character in a Sentence

Classify every char of a short sentence and count five categories.

Java
public class CharacterGetTypeCount {
    public static void main(String[] args) {
        String text = "Hello, World 42!";
        int upper = 0, lower = 0, digits = 0, spaces = 0, punct = 0;
        for (int i = 0; i < text.length(); i++) {
            int t = Character.getType(text.charAt(i));
            if (t == Character.UPPERCASE_LETTER) upper++;
            else if (t == Character.LOWERCASE_LETTER) lower++;
            else if (t == Character.DECIMAL_DIGIT_NUMBER) digits++;
            else if (t == Character.SPACE_SEPARATOR) spaces++;
            else if (t == Character.OTHER_PUNCTUATION) punct++;
        }
        System.out.println("upper=" + upper + " lower=" + lower + " digits=" + digits
                + " spaces=" + spaces + " punctuation=" + punct);
    }
}

How It Works

  1. One call per char. getType runs once for each of the 16 chars, and the result is compared with named constants.
  2. Letters by case. H and W are uppercase; e, l, l, o, o, r, l, d are the 8 lowercase letters.
  3. Other punctuation. Both ',' and '!' are in the OTHER_PUNCTUATION category, giving 2.

Example 3 — Categories of an Emoji, a Surrogate, Private Use, and an Unassigned Code Point

Use the int overload, and see what the char overload says about half of a surrogate pair.

Java
public class CharacterGetTypeCodePoints {
    public static void main(String[] args) {
        System.out.println("U+1F600: " + Character.getType(0x1F600)
                + " other symbol=" + (Character.getType(0x1F600) == Character.OTHER_SYMBOL));
        System.out.println("0xd83d char: " + Character.getType('\uD83D')
                + " surrogate=" + (Character.getType('\uD83D') == Character.SURROGATE));
        System.out.println("U+E000: " + Character.getType(0xE000)
                + " private use=" + (Character.getType(0xE000) == Character.PRIVATE_USE));
        System.out.println("U+10FFFF: " + Character.getType(0x10FFFF)
                + " unassigned=" + (Character.getType(0x10FFFF) == Character.UNASSIGNED));
    }
}

How It Works

  1. The whole emoji. Passed as a code point, U+1F600 is OTHER_SYMBOL (28).
  2. Half an emoji. Its high surrogate on its own is only SURROGATE (19), which is why text should be classified by code point.
  3. Reserved values. U+E000 is set aside for private use (18), and U+10FFFF is a permanent noncharacter, so it is UNASSIGNED (0) in every Unicode version.

Frequently Asked Questions

An int for the Unicode general category, matching a constant such as Character.UPPERCASE_LETTER (1) or Character.DECIMAL_DIGIT_NUMBER (9).
There is no built-in method. Map the constants yourself, for example with a switch.
Character.UNASSIGNED, which is 0.
Emoji above U+FFFF are two chars. Each half alone is a surrogate; call getType with the code point instead.
They are declared as byte; they widen to int automatically in comparisons.

Next: hashCode()

Get the hash code of a char: simply its numeric value.

hashCode() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful