Skip to content
Related Articles

Related Articles

Character.getDirectionality() method in Java with examples
  • Last Updated : 06 Dec, 2018

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)

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :