当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。