📜  Java中的字符.isIdentifierIgnorable() 和示例

📅  最后修改于: 2022-05-13 01:55:00.203000             🧑  作者: Mango

Java中的字符.isIdentifierIgnorable() 和示例

  1. Java.lang。 字符.isIdentifierIgnorable(char ch)是Java中的一个内置方法,用于确定指定字符是否应被视为Java标识符或 Unicode 标识符中的可忽略字符。

    在Java标识符或 Unicode 标识符中可以忽略以下 Unicode字符:

    • 非空白的 ISO 控制字符
      1. '\u0000' 到 '\u0008'
      2. '\u000E' 到 '\u001B'
      3. '\u007F' 到 '\u009F'
    • 所有具有 FORMAT 通用类别值的字符

    句法:

    public static boolean isIdentifierIgnorable(char ch)

    参数:参数ch是字符数据类型,指的是要测试的字符。

    返回值:如果字符是可以是Java或 Unicode 标识符的一部分的可忽略控制字符,则此方法返回 true,否则返回 false。

    下面的程序说明了字符.isIdentifierIgnorable(char ch) 方法:

    方案一:

    // 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
    

    方案二:

    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。 字符.isIdentifierIgnorable(int codePoint)在所有方面都类似于前面的方法。

    句法:

    public static boolean isIdentifierIgnorable(int codePoint)
    

    参数:该函数接受一个整数数据类型的参数 codePoint,它指定要测试的字符(Unicode 代码点)。

    返回值:如果字符是可以是Java或 Unicode 标识符的一部分的可忽略控制字符,则此方法返回 true,否则返回 false。

    下面的程序说明了字符.isIdentifierIgnorable(int codepoint) 方法:
    方案一:

    // 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
    

    方案二:

    // 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: Java/lang/ 字符.html#isIdentifierIgnorable(char)