当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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)



相关用法


注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 Character.getDirectionality() method in Java with examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。