Java Character getDirectionality() Method

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

Definition

In Java, Character.getDirectionality(ch) returns the character's bidirectional class: how it behaves when text mixes left-to-right scripts (such as Latin) with right-to-left scripts (such as Hebrew and Arabic). Latin letters are DIRECTIONALITY_LEFT_TO_RIGHT (0), Hebrew letters DIRECTIONALITY_RIGHT_TO_LEFT (1), and Arabic letters DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC (2).

The result is a byte. Digits, spaces, and punctuation are "weak" or "neutral": their direction depends on nearby text. Undefined chars return DIRECTIONALITY_UNDEFINED (-1).

A static method of java.lang.Character (Java 1.4+): call it on the class, as in Character.getDirectionality(...); 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 byte result with the constants.

Java
Character.getDirectionality('A') == Character.DIRECTIONALITY_LEFT_TO_RIGHT        // true (0)
Character.getDirectionality('\u05D0') == Character.DIRECTIONALITY_RIGHT_TO_LEFT   // true (1), Hebrew alef
Character.getDirectionality('5') == Character.DIRECTIONALITY_EUROPEAN_NUMBER      // true (3)
Character.getDirectionality(' ') == Character.DIRECTIONALITY_WHITESPACE           // true (12)
CallWhat it does
byte d = Character.getDirectionality(c);Store the class.
d == Character.DIRECTIONALITY_RIGHT_TO_LEFTIs this a (non-Arabic) right-to-left letter?
Character.getDirectionality(s.codePointAt(i))The class of a character above U+FFFF.

Two overloads: getDirectionality(char ch) since Java 1.4 and getDirectionality(int codePoint) since Java 5. For full bidirectional layout, use java.text.Bidi.

Library declarations
Java
// java.lang.Character
public static byte getDirectionality(char ch)          // Java 1.4
public static byte getDirectionality(int codePoint)    // Java 5

public static final byte DIRECTIONALITY_UNDEFINED = -1;
public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0;
public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1;

Parameters

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

Return Value

Return ValueDescription
byteA DIRECTIONALITY_* constant, or DIRECTIONALITY_UNDEFINED (-1).

Compare with Similar Methods

Related properties:

MethodHow it differs
isMirrored(ch)Whether the glyph flips in right-to-left text.
getType(ch)The general category, a different property.
java.text.BidiLays out whole paragraphs of mixed-direction text.

Java Examples

Example 1 — The Bidirectional Class of Seven Characters

Check letters from three scripts, a digit, a plus sign, a space, and '!'.

Java
public class CharacterGetDirectionalityTable {
    static String name(byte d) {
        switch (d) {
            case Character.DIRECTIONALITY_LEFT_TO_RIGHT: return "LEFT_TO_RIGHT";
            case Character.DIRECTIONALITY_RIGHT_TO_LEFT: return "RIGHT_TO_LEFT";
            case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC: return "RIGHT_TO_LEFT_ARABIC";
            case Character.DIRECTIONALITY_EUROPEAN_NUMBER: return "EUROPEAN_NUMBER";
            case Character.DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR: return "EUROPEAN_NUMBER_SEPARATOR";
            case Character.DIRECTIONALITY_WHITESPACE: return "WHITESPACE";
            case Character.DIRECTIONALITY_OTHER_NEUTRALS: return "OTHER_NEUTRALS";
            default: return "other";
        }
    }

    public static void main(String[] args) {
        char[] chars = {'A', '\u05D0', '\u0627', '5', '+', ' ', '!'};
        for (char c : chars) {
            byte d = Character.getDirectionality(c);
            System.out.println("0x" + Integer.toHexString(c) + " " + d + " " + name(d));
        }
    }
}

How It Works

  1. Strong classes. Latin 'A' is left-to-right, Hebrew alef (U+05D0) right-to-left, and Arabic alef (U+0627) right-to-left Arabic.
  2. Weak classes. The digit and the plus sign are "European number" and "European number separator": they follow the direction of nearby text.
  3. Neutral classes. Space and '!' take the direction of their surroundings; a byte switch maps each value to a readable name.

Example 2 — Does a String Contain Right-to-Left Letters?

Scan for chars whose class is right-to-left or right-to-left Arabic. Only booleans are printed.

Java
public class CharacterGetDirectionalityRtl {
    static boolean hasRtl(String s) {
        for (int i = 0; i < s.length(); i++) {
            byte d = Character.getDirectionality(s.charAt(i));
            if (d == Character.DIRECTIONALITY_RIGHT_TO_LEFT
                    || d == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println("English: " + hasRtl("hello"));
        System.out.println("Hebrew:  " + hasRtl("\u05E9\u05DC\u05D5\u05DD"));
        System.out.println("Mixed:   " + hasRtl("abc \u0645\u0631\u062D\u0628\u0627"));
        System.out.println("Digits:  " + hasRtl("2024"));
    }
}

How It Works

  1. Two right-to-left classes. Hebrew letters report class 1 and Arabic letters class 2, so the check accepts both.
  2. Mixed text. "abc " is left-to-right, but the Arabic word after it makes the result true.
  3. Digits are not strong. European digits are a weak class, so "2024" contains no right-to-left letters.

Example 3 — Directionality of Characters Above U+FFFF

Use the int overload for a math letter, an emoji, and a Phoenician letter, and store the results as bytes.

Java
public class CharacterGetDirectionalityCodePoints {
    public static void main(String[] args) {
        byte math = Character.getDirectionality(0x1D400);
        byte emoji = Character.getDirectionality(0x1F600);
        byte phoenician = Character.getDirectionality(0x10900);
        System.out.println("math letter LTR: " + (math == Character.DIRECTIONALITY_LEFT_TO_RIGHT));
        System.out.println("emoji neutral:   " + (emoji == Character.DIRECTIONALITY_OTHER_NEUTRALS));
        System.out.println("Phoenician RTL:  " + (phoenician == Character.DIRECTIONALITY_RIGHT_TO_LEFT));
        System.out.println("byte values: " + math + ", " + emoji + ", " + phoenician);
    }
}

How It Works

  1. Supplementary letters. MATHEMATICAL BOLD CAPITAL A (U+1D400) is left-to-right, while PHOENICIAN LETTER ALF (U+10900) is right-to-left.
  2. Emoji are neutral. U+1F600 has the "other neutrals" class (13), so it follows the surrounding text direction.
  3. Stored as bytes. The return type is byte, which easily holds every class value.

Frequently Asked Questions

A byte constant for the bidirectional class, such as DIRECTIONALITY_LEFT_TO_RIGHT (0) or DIRECTIONALITY_RIGHT_TO_LEFT (1).
Look for chars whose class is DIRECTIONALITY_RIGHT_TO_LEFT or DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC.
It is -1, for chars with no defined directionality.
They are weak or neutral classes: their direction depends on nearby letters.
No. It classifies one character. Use java.text.Bidi to analyse whole paragraphs.

Next: getName()

Get the official Unicode name of a code point, such as LATIN CAPITAL LETTER A (Java 7+).

getName() 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.

9 people found this page helpful