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


Java Character.isHighSurrogate()用法及代碼示例


java.lang.Character.isHighSurrogate()是java中的內置方法,它確定給定的char值是否為Unicode high-surrogate代碼單元(也稱為leading-surrogate代碼單元)。這樣的值本身並不表示字符,而是用於UTF-16編碼中的補充字符。

用法:

public static boolean isHighSurrogate(char ch)

參數:該函數接受單個強製參數ch,該參數指定要測試的值。


返回值:該函數返回一個布爾值。如果char值介於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


相關用法


注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 Character.isHighSurrogate() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。