Java Character isValidCodePoint()方法及示例

Java Character isValidCodePoint()方法及示例

Character.isValidCodePoint() 是java中的一个内置方法,用于确定参数中提到的指定码位是否是有效的Unicode码位值。

语法

public static boolean isValidCodePoint(int codePoint)

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

返回值: 如果指定的码位值在MIN_CODE_POINT和MAX_CODE_POINT之间,该方法返回真,否则返回假。

下面的程序说明了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)

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Java 参考指南