Tuesday, June 16, 2026
HomeLanguagesJavaCharacter.getDirectionality() method in Java with examples

Character.getDirectionality() method in Java with examples

The java.lang.Character.getDirectionality() is an inbuilt method in Java which returns the Unicode directionality property for the given character. Character directionality is used to calculate the visual ordering of text. The directionality value of undefined char values is DIRECTIONALITY_UNDEFINED. This method cannot handle supplementary characters. In order to support all the Unicode characters including supplementary characters, pass an integer in the parameter of this method.

Syntax:

public static byte getDirectionality(char ch)

Parameters: The function accepts one parameter ch which is mandatory. This parameter specifies the char for which the directionality property is requested. The parameter can be of int or char data type.

Return value: The function returns byte which denotes the directionality property of the char value.

Below programs illustrate the above method:

Program 1:




// Java program to demonstrate the
// Character.getDirectionality() method
// when the passed parameter is an integer
import java.lang.*;
  
public class gfg {
  
    public static void main(String[] args)
    {
        // create 2 int primitives ch1 and
        // ch2 and assign values to them
        int ch1=0x2424, ch2=0x2c61;
  
        // assign directionality of ch1, ch2 to bp1, bp2
        byte b1 = Character.getDirectionality(ch1);
        byte b2 = Character.getDirectionality(ch2);
  
        System.out.println("Directionality of first primitive is " + b1);
        System.out.println("Directionality of first primitive is " + b2);
    }
}


Output:

Directionality of first primitive is 13
Directionality of first primitive is 0

Program 2:




// Java program to demonstrate the
// Character.getDirectionality() method
// when the passed parameter is a character
import java.lang.*;
  
public class gfg {
  
    public static void main(String[] args)
    {
        // create 2 int primitives ch1 and
        // ch2 and assign values to them
        char ch1 = 'M', ch2 = '\u06ff';
  
        // assign directionality of ch1, ch2 to bp1, bp2
        byte b1 = Character.getDirectionality(ch1);
        byte b2 = Character.getDirectionality(ch2);
  
        System.out.println("Directionality of first primitive is " + b1);
        System.out.println("Directionality of first primitive is " + b2);
    }
}


Output:

Directionality of first primitive is 0
Directionality of first primitive is 2

Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#getDirectionality(char)

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS