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


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


Character.isValidCodePoint()是Java中的一种内置方法,该方法确定参数中提到的指定代码点是否为有效的Unicode代码点值。

用法:

public static boolean isValidCodePoint(int codePoint)


参数:
参数codePoint是Integer数据类型,是指要测试的unicode代码点。


返回值:如果指定的代码点值在MIN_CODE_POINT和MAX_CODE_POINT(含)之间,则此方法返回true,否则返回false。

下面的程序演示了Character.isValidCodePoint()方法的使用:
示例1:

// Java program to demonstrate the 
// Character.isValidCodePoint() method 
import java.lang.*; 
  
public class gfg { 
  
    public static void main(String[] args) 
    { 
  
        // Create 2 int primitives c1, c2 and assign values 
        int c1 = 0x0125, c2 = 0x123fff; 
  
        boolean bool1 = Character.isValidCodePoint(c1); 
        boolean bool2 = Character.isValidCodePoint(c2); 
  
        String str1 = "c1 is a valid Unicode code point is " + bool1; 
        String str2 = "c2 is a valid Unicode code point is " + bool2; 
  
        // Print bool1, bool2 values 
        System.out.println(str1); 
        System.out.println(str2); 
    } 
}
输出:
c1 is a valid Unicode code point is true
c2 is a valid Unicode code point is false

示例2:

// Java program to demonstrate the 
// Character.isValidCodePoint() method  
import java.lang.*; 
  
public class gfg { 
  
    public static void main(String[] args) 
    { 
  
        // Create 2 int primitives c1, c2 and assign values 
        int c1 = 0x0128, c2 = 0x123ddd; 
  
        boolean bool1 = Character.isValidCodePoint(c1); 
        boolean bool2 = Character.isValidCodePoint(c2); 
  
        String str1 = "c1 is a valid Unicode code point is " + bool1; 
        String str2 = "c2 is a valid Unicode code point is " + bool2; 
  
        // Print bool1, bool2 values 
        System.out.println(str1); 
        System.out.println(str2); 
    } 
}
输出:
c1 is a valid Unicode code point is true
c2 is a valid Unicode code point is false

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



相关用法


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