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


Java Character.isIdentifierIgnorable()用法及代碼示例


  1. java.lang.Character.isIdentifierIgnorable(char ch)是java中的一種內置方法,該方法確定應將指定字符視為Java標識符還是Unicode標識符中的可忽略字符。

    以下Unicode字符在Java標識符或Unicode標識符中可忽略:

    • 非空白的ISO控製字符
      1. “ \ u0000”到“ \ u0008”
      2. “ \ u000E”到“ \ u001B”
      3. 從'\ u007F'到'\ u009F'
    • 具有FORMAT常規類別值的所有字符

    用法:


    public static boolean isIdentifierIgnorable(char ch)

    參數:參數ch是字符數據類型,是指要測試的字符。

    返回值:如果該字符是Java或Unicode標識符的一部分的可忽略控製字符,則此方法返回true,否則返回false。

    以下示例程序旨在說明Character.isIdentifierIgnorable(char ch)方法:

    示例1:

    // Java program to illustrate 
    // Character.isIdentifierIgnorable(char ch) method 
    import java.lang.*; 
      
    public class gfg { 
      
       public static void main(String[] args) { 
      
          // Creates 2 character primitives c1, c2 and assigning values 
          char c1='\u0000', c2= '9'; 
      
          // Assigns isIdentifierIgnorable results of  
          // c1, c2 to boolean primitives 
          boolean  bool1 = Character.isIdentifierIgnorable(c1); 
          boolean  bool2 = Character.isIdentifierIgnorable(c2); 
      
          String str1 = "c1 is an ignorable control character is " + bool1; 
          String str2 = "c2 is an ignorable control character is " + bool2; 
      
          System.out.println( str1 ); 
          System.out.println( str2 ); 
       } 
    }
    輸出:
    c1 is an ignorable control character is true
    c2 is an ignorable control character is false
    

    示例2:

    import java.lang.*; 
      
    public class gfg { 
      
       public static void main(String[] args) { 
      
          // Create 2 character primitives c1, c2 and assigning values 
          char c1='\u000E', c2= '8'; 
      
          // Assigns isIdentifierIgnorable results of  
          // c1, c2 to boolean primitives 
          boolean  bool1 = Character.isIdentifierIgnorable(c1); 
          boolean  bool2 = Character.isIdentifierIgnorable(c2); 
      
          String str1 = "c1 is an ignorable control character is " + bool1; 
          String str2 = "c2 is an ignorable control character is " + bool2; 
      
          System.out.println( str1 ); 
          System.out.println( str2 ); 
       } 
    }
    輸出:
    c1 is an ignorable control character is true
    c2 is an ignorable control character is false
    
  2. java.lang.Character.isIdentifierIgnorable(int codePoint)在所有方麵都類似於先前的方法。

    用法:

    public static boolean isIdentifierIgnorable(int codePoint)
    

    參數:該函數接受整數數據類型的單個參數codePoint,該參數指定要測試的字符(Unicode代碼點)。

    返回值:如果該字符是Java或Unicode標識符的一部分的可忽略控製字符,則此方法返回true,否則返回false。


    以下示例程序旨在說明Character.isIdentifierIgnorable(int codepoint)方法:
    示例1:

    // Java program to demonstrate  
    // the Character.isIdentifierIgnorable(int codepoint) method 
      
    import java.lang.*; 
      
    public class gfg { 
      
       public static void main(String[] args) { 
      
          // Integer primitives c1, c2 
          int c1 = 0x019f, c2 = 0x1abc; 
      
          // Assign isIdentifierIgnorable results of cp1, cp2 
          // to boolean primitives bool1, bool2 
         boolean bool1 = Character.isIdentifierIgnorable(c1); 
         boolean bool2 = Character.isIdentifierIgnorable(c2); 
      
          // Print bool1, bool2 values 
          System.out.println( "c1 is an ignorable control character?"+ 
          " ans is "+bool1); 
          System.out.println( "c2 is an ignorable control character?"+ 
          " ans is "+bool2); 
       } 
    }
    輸出:
    c1 is an ignorable control character? ans is false
    c2 is an ignorable control character? ans is false
    

    示例2:

    // Java program to demonstrate  
    // the Character.isIdentifierIgnorable(int codepoint) method 
      
    import java.lang.*; 
      
    public class gfg { 
      
       public static void main(String[] args) { 
      
          // Integer primitives c1, c2 
          int c1 = 0x119f, c2 = 0x0abc; 
      
          // Assign isIdentifierIgnorable results of cp1, cp2 
          // to boolean primitives bool1, bool2 
         boolean bool1 = Character.isIdentifierIgnorable(c1); 
         boolean bool2 = Character.isIdentifierIgnorable(c2); 
      
          // Print bool1, bool2 values 
          System.out.println( "c1 is an ignorable control character?"+ 
          " ans is "+bool1); 
          System.out.println( "c2 is an ignorable control character?"+ 
          " ans is "+bool2); 
       } 
    }
    輸出:
    c1 is an ignorable control character? ans is false
    c2 is an ignorable control character? ans is false
    

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



相關用法


注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 Character.isIdentifierIgnorable() in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。