📜  Java中的字符.getDirectionality() 方法及示例

📅  最后修改于: 2022-05-13 01:54:19.599000             🧑  作者: Mango

Java中的字符.getDirectionality() 方法及示例

Java.lang。 字符.getDirectionality()是Java中的一个内置方法,它返回给定字符的 Unicode 方向性属性。字符方向性用于计算文本的视觉顺序。未定义字符值的方向性值为 DIRECTIONALITY_UNDEFINED。此方法无法处理补充字符。为了支持包括补充字符在内的所有 Unicode字符,请在此方法的参数中传递一个整数。

句法:

public static byte getDirectionality(char ch)

参数:该函数接受一个强制参数ch 。此参数指定为其请求方向性属性的字符。该参数可以是 int 或 char 数据类型。

返回值:函数返回字节,表示char值的方向性。

下面的程序说明了上述方法:

方案一:

// 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

方案二:

// 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: Java/lang/ 字符.html#getDirectionality(char)