New Tutorials:   NUMPY    TKINTER    KOTLIN    JAVASCRIPT    SASS/SCSS    PL/SQL    Matplotlib    C++ Programs

Java Character getDirectionality(int codePoint) Method

Java getDirectionality() method is a part of Character class. This method is used to return the property of Unicode directionality of the specified character(Unicode code point) which is basically the property that calculates the visual ordering of the text.

The value DIRECTIONALITY_UNDEFINED is returned for undefined char value.

Syntax:

public static byte getDirectionality(int codePoint) 

Parameter:

The parameter passed is the Unicode codepoint value whose Character Directionality is to be returned.

Returns:

Returns the directionality property of the Unicode codepoint value.

Example 1:

Here, the directionality property of the characters (Unicode codepoint value) is returned.

public class StudyTonight 
{  
    public static void main(String[] args)
    {         
      int n1 = 45;  
      int n2 = 98;  
      byte b1 = Character.getDirectionality(n1);  
      byte b2 = Character.getDirectionality(n2);   
      System.out.println("The directionality of " + (char)n1 + " is " + b1);  
      System.out.println("The directionality of " + (char)n2 + " is " + b2);          
    }  
}  


The directionality of - is 4
The directionality of b is 0

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the desired result.

import java.util.Scanner;
public class StudyTonight 
{  
	public static void main(String[] args)
	{         
		try
		{
			System.out.print("Enter the codepoint value:");  
			Scanner sc = new Scanner(System.in);  
			int n = sc.nextInt();  

			byte r = Character.getDirectionality(n);   
			System.out.println("The directionality property of " + (char)n + " is " + r);       
		}       
		catch(Exception e)
		{
			System.out.println("Invalid error");
		}
	}
} 


Enter the codepoint value: 55
The directionality property of 7 is 3
*********************************************
Enter the codepoint value: 101
The directionality property of e is 0

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.