當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。