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

Java Character getDirectionality(char ch)

Java getDirectionality() method is a part of Character class. Character directionality is basically the property that calculates the visual ordering of the text and this method is used to return the property of Unicode directionality for the given character.

Note: The value DIRECTIONALITY_UNDEFINED is returned for undefined char value.

Syntax:

public static byte getDirectionality(char ch) 

Parameter:

The parameter passed is the character value whose Character directionality is to be returned.

Returns:

Returns the directionality property of the char value.

Example 1:

Here, the directionality property of the characters is returned by using the getDirectionality() method.

public class StudyTonight 
{  
	public static void main(String[] args)
	{         
		char ch1 = 'M';  
		char ch2 = '8';  
		byte b1 = Character.getDirectionality(ch1);  
		byte b2 = Character.getDirectionality(ch2);  
		System.out.println("The directionality of " + ch1 + " is " + b1);  
		System.out.println("The directionality of " + ch2 + " is " + b2);  
	}  
}  


The directionality of M is 0
The directionality of 8 is 3

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 value:");  
			Scanner sc = new Scanner(System.in);  
			char[] val = sc.nextLine().toCharArray();  

			for (char ch : val)
			{  
				byte r = Character.getDirectionality(ch);   
				System.out.println("The directionality property for the character " + ch+ " is " + r);       
			}
		}
		catch(Exception e)
		{
			System.out.println("Invalid error");
		}
	}
}  


Enter the value: mohit
The directionality property for the character m is 0
The directionality property for the character o is 0
The directionality property for the character h is 0
The directionality property for the character i is 0
The directionality property for the character t is 0
*************************************************************
Enter the value: 1001
The directionality property for the character 1 is 3
The directionality property for the character 0 is 3
The directionality property for the character 0 is 3
The directionality property for the character 1 is 3

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.