Java Character getDirectionality()方法

java.lang.Character.getDirectionality(char ch) 返回给定字符Unicode的方向属性。字符指向来计算文本的视觉顺序。未定义的char值的方向性值为DIRECTIONALITY_UNDEFINED。

1 语法

public static byte getDirectionality(char ch)

2 参数

ch:字符为其指向属性要求

3 返回值

此方法返回char值的方向属性。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java Character getDirectionality()方法
 */
import java.lang.*;

public class CharacterDemo {

   public static void main(String[] args) {

      // create 2 character primitives ch1, ch2
      char ch1, ch2;

      // assign values to ch1, ch2
      ch1 = 'M';
      ch2 = 'u06ff';

      // create 2 byte primitives b1, b2
      byte b1, b2;

      // assign directionality of ch1, ch2 to b1, b2
      b1 = Character.getDirectionality(ch1);
      b2 = Character.getDirectionality(ch2);

      /**
       *  byte value 0 represents DIRECTIONALITY_LEFT_TO_RIGHT
       *  byte value 2 represents DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC
       */

      String str1 = "Directionality of " + ch1 + " is " + b1;
      String str2 = "Directionality of ch2 is " + b2;

      // print b1, b2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

输出结果为:

Directionality of M is 0 
Directionality of ch2 is 2

 

热门文章

优秀文章