Java Character getDirectionality()方法及示例
java.lang.Character.getDirectionality() 是Java中的一个内置方法,用于返回指定字符的Unicode方向性属性。字符方向性用于计算文本的视觉排序。未定义的char值的方向性值是DIRECTIONALITY_UNDEFINED。这个方法不能处理补充字符。为了支持所有的Unicode字符,包括补充字符,请在此方法的参数中传递一个整数。
语法
public static byte getDirectionality(char ch)
参数: 该函数接受一个参数 ch ,这是必须的。这个参数指定了要求方向性属性的char。该参数可以是int或char数据类型。
返回值: 该函数返回字节,该字节表示char值的方向性属性。
以下程序说明了上述方法。
程序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);
}
}
输出:
Directionality of first primitive is 13
Directionality of first primitive is 0
程序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);
}
}
输出:
Directionality of first primitive is 0
Directionality of first primitive is 2
参考资料 : https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#getDirectionality(char)