Java Character isHighSurrogate()方法及示例

Java Character isHighSurrogate()方法及示例

java.lang.Character.isHighSurrogate() 是java中的一个内置方法,它可以确定给定的char值是否是Unicode高代用代码单元(也被称为领先代用代码单元)。这种值本身并不代表字符,但在UTF-16编码中用于表示补充字符。

语法

public static boolean isHighSurrogate(char ch)

参数: 该函数接受一个强制参数ch,它指定了要测试的值。

返回值: 该函数返回一个布尔值。如果字符值在MIN_HIGH_SURROGATE和MAX_HIGH_SURROGATE之间,返回值为True,否则为False。

以下程序说明了Character.isHighSurrogate()方法。

程序1 :

// Java program to illustrate the
// Character.isHighSurrogate() method
import java.lang.*;
  
public class gfg {
  
    public static void main(String[] args)
    {
  
        // create 2 char primitives c1, c2
        char c1 = '\u0a4f', c2 = '\ud8b4';
  
        // assign isHighSurrogate results of
        // c1, c2 to boolean primitives bool1, bool2
        boolean bool1 = Character.isHighSurrogate(c1);
        System.out.println("c1 is a Unicode"+
        "high-surrogate code unit ? " + bool1);
  
        boolean bool2 = Character.isHighSurrogate(c2);
        System.out.println("c2 is a Unicode"+ 
        "high-surrogate code unit ? " + bool2);
    }
}

输出:

c1 is a Unicodehigh-surrogate code unit ? false
c2 is a Unicodehigh-surrogate code unit ? true

程序2

// Java program to illustrate the
// Character.isHighSurrogate() method
import java.lang.*;
  
public class gfg {
  
    public static void main(String[] args)
    {
  
        // create 2 char primitives c1, c2
        char c1 = '\u0b9f', c2 = '\ud5d5';
  
        // assign isHighSurrogate results of
        // c1, c2 to boolean primitives bool1, bool2
        boolean bool1 = Character.isHighSurrogate(c1);
        System.out.println("c1 is a Unicode" + 
        "high-surrogate code unit ? " + bool1);
  
        boolean bool2 = Character.isHighSurrogate(c2);
        System.out.println("c2 is a Unicode" + 
        "high-surrogate code unit ? " + bool2);
    }
}

输出:

c1 is a Unicodehigh-surrogate code unit ? false
c2 is a Unicodehigh-surrogate code unit ? false

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Java 参考指南