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


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。