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


Java Character.isLowSurrogate()用法及代码示例


java.lang.Character.isLowSurrogate(char ch)是java中的一种内置方法,它确定给定的char值是否为Unicode low-surrogate代码单元(也称为trailing-surrogate代码单元)。这样的值本身并不表示字符,而是用于UTF-16编码中的补充字符。

用法:

public static boolean isLowSurrogate(char ch)

参数:该函数接受一个强制性参数ch,该参数指定要测试的字符。


返回值:该函数返回一个布尔值。如果char值介于MIN_LOW_SURROGATE和MAX_LOW_SURROGATE(含)之间,则返回的值为True,否则为False。

以下示例程序旨在说明Character.isLowSurrogate()方法:

示例1:

// Java program to illustrate the 
// Character.isLowSurrogate() method 
import java.lang.*; 
  
public class gfg { 
  
    public static void main(String[] args) 
    { 
  
        // create 2 char primitives c1, c2 
        char c1 = '\udc25', c2 = 'h'; 
  
        // assign isLowSurrogate results of 
        // c1, c2 to boolean primitives bool1, bool2 
        boolean bool1 = Character.isLowSurrogate(c1); 
        System.out.println("c1 is a Unicode low-surrogate ? " + bool1); 
  
        boolean bool2 = Character.isLowSurrogate(c2); 
        System.out.println(c2 + " is a Unicode low-surrogate ? " + bool2); 
    } 
}
输出:
c1 is a Unicode low-surrogate ? true
h is a Unicode low-surrogate ? false

示例2:

// Java program to illustrate the 
// Character.isLowSurrogate() method 
import java.lang.*; 
  
public class gfg { 
  
    public static void main(String[] args) 
    { 
  
        // create 2 char primitives c1, c2 
        char c1 = '\udc29', c2 = 'x'; 
  
        // assign isLowSurrogate results of 
        // c1, c2 to boolean primitives bool1, bool2 
        boolean bool1 = Character.isLowSurrogate(c1); 
        System.out.println("c1 is a Unicode low-surrogate ? " + bool1); 
  
        boolean bool2 = Character.isLowSurrogate(c2); 
        System.out.println(c2 + " is a Unicode low-surrogate ? " + bool2); 
    } 
}
输出:
c1 is a Unicode low-surrogate ? true
x is a Unicode low-surrogate ? false

参考: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isLowSurrogate(char)



相关用法


注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 Character.isLowSurrogate() method in Java with examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。