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


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


Character 類的 isHighSurrogate(char ch) 方法判斷給定值是否為高代理代碼單元,也稱為前導代理代碼單元。

這些值本身不能用於表示字符,但可以用於表示 UTF-16 編碼中的增補字符。

用法

public static boolean isHighSurrogate(char ch)

參數

上述方法隻需要一個參數:

a.)需要測試的字符值。

返回值

isHighSurrogate(char ch) 方法返回一個布爾值,即如果字符的值位於 MIN_HIGH_SURROGATE 和 MAX_HIGH_SURROGATE 之間,則返回 true。否則,此方法返回 false。

例子1

public class JavaCharacterisHighSurrogateExample1 {
	public static void main(String[] args) {
	  // Initialize the characters that need to be tested.
		char c1 = '\ud800';
		char c2 = '\uc71f';
		char c3 = '\u1016';	
	// Check the individual character whether it is 
		boolean result1 = Character.isHighSurrogate(c1);
		boolean result2 = Character.isHighSurrogate(c2);
		boolean result3 = Character.isHighSurrogate(c3);
	// print the result
System.out.println("The first character is a Unicode high-surrogate code unit:"+  result1);
System.out.println("The second character is a Unicode high-surrogate code unit:"+  result2);	
System.out.println("The third character is a Unicode high-surrogate code unit:"+  result3);	
	}
}

輸出:

The first character is a Unicode high-surrogate code unit:true
The second character is a Unicode high-surrogate code unit:false
The third character is a Unicode high-surrogate code unit:false

例子2

public class JavaCharacterisHighSurrogateExample2 {
	public static void main(String args[])
	{
   //Initialize two char value
	  char a1 ='Z';
	  char a2 ='z';
  //Create two object obj1 and obj2.
	  Character obj1 =new Character(a1);   
	  Character obj2 =new Character(a2);   
  //Check whether the given charactesr 'obj' and 'obj2' are isHighSurrogate or not.
	  boolean b1 = obj1.isHighSurrogate(a1);  
	  boolean b2 = obj2.isHighSurrogate(a2);  
  //Print the values.
	  System.err.println("The character 'Z' is a Unicode high-surrogate code unit:"+b1);        
	  System.err.println("The character 'z' is a Unicode high-surrogate code unit:"+b2);        
     }
}

輸出:

The character 'Z' is a Unicode high-surrogate code unit:false
The character 'z' is a Unicode high-surrogate code unit:false





相關用法


注:本文由純淨天空篩選整理自 Java Character isHighSurrogate() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。