Java Character isHighSurrogate()方法

java.lang.Character.isHighSurrogate(char ch) 判断给定char值是Unicode高代理项代码单元(也称为高级代理项代码单元)。

这个值并不代表字符本身,而是在UTF-16编码的补充的字符的表示被使用。

1 语法

public static boolean isHighSurrogate(char ch)

2 参数

ch:待测试的char值

3 返回值

如果char值是MIN_HIGH_SURROGATE和MAX_HIGH_SURROGATE(含)之间此方法返回true,否则返回false。

4 示例 

package com.yiidian;

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

public class CharacterDemo {

   public static void main(String[] args) {

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

      // assign values to ch1, ch2
      ch1 = 'u0c7f';
      ch2 = 'ud8b5';

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

      // assign isHighSurrogate results of ch1, ch2 to b1, b2
      b1 = Character.isHighSurrogate(ch1);
      b2 = Character.isHighSurrogate(ch2);

      String str1 = "ch1 is a Unicode high-surrogate code unit is " + b1;
      String str2 = "ch2 is a Unicode high-surrogate code unit is " + b2;

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

输出结果为:

ch1 is a Unicode high-surrogate code unit is false
ch2 is a Unicode high-surrogate code unit is true

 

热门文章

优秀文章