性格Java中的isIdentifierIgnorable()及其示例

  1. 这个 JAVA朗,性格。isIdentifierIgnorable(字符ch) 是java中的一种内置方法,用于确定指定字符在java标识符或Unicode标识符中应被视为可忽略字符。

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

    • 非空白的ISO控制字符
      1. “u0000”到“u0008”
      2. “u000E”至“u001B”
      3. “u007F”到“u009F”
    • 具有格式“常规”类别值的所有字符

    语法:

    public static boolean isIdentifierIgnorable(char ch)

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

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

    下面的程序说明了这个角色。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朗,性格。isIdentifierIgnorable(int代码点) 在所有方面都与前面的方法类似。

    语法:

    public static boolean isIdentifierIgnorable(int codePoint)
    

    参数: 该函数接受integer数据类型的单参数代码点,指定要测试的字符(Unicode代码点)。

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

    下面的程序演示了这个角色。isIdentifierIgnorable(int代码点)方法: 项目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(字符)

© 版权声明
THE END
喜欢就支持一下吧,技术咨询可以联系QQ407933975
点赞14 分享