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:
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
int ch1= 0x2424 , ch2= 0x2c61 ;
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:
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
char ch1 = 'M' , ch2 = '\u06ff' ;
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)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...