Java Character isIdentifierIgnorable()示例

Java Character isIdentifierIgnorable()示例

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

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

  • 不是空白的ISO控制字符
      1. ‘u/0000’到’u/0008’。
    1. ‘\u000E’ 到 ‘\u001B’ 2.
    2. ‘\u007F’ 到 ‘\u009F’ 3.
  • 所有具有FORMAT一般类别值的字符

语法:

public static boolean isIdentifierIgnorable(char ch)

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

返回值:如果该字符是一个可忽略的控制字符,可能是Java或Unicode标识符的一部分,则该方法返回真,否则返回假。

下面的程序说明了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
  1. java.lang.Character.isIdentifierIgnorable(int codePoint)在所有方式上都与前一个方法类似。

语法:

public static boolean isIdentifierIgnorable(int codePoint)

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

返回值:如果该字符是一个可忽略的控制字符,可能是Java或Unicode标识符的一部分,则该方法返回真,否则返回假。

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Java 参考指南