Java Character isIdentifierIgnorable() 方法

2024年11月6日 | 阅读时长 5 分钟

Character 类的 isIdentifierIgnorable(int codePoint) 方法通常用于确定指定的字符在 Java 或 Unicode 标识符中是否可以被视为可忽略字符。

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

  • 不具有空白的 ISO 控制字符。
  • 所有具有 FORMAT 通用类别值的字符。

语法

参数

上述方法只需要一个参数

a.) codePoint,即需要测试的字符。

返回值

isIdentifierIgnorable(int codePoint) 方法返回一个布尔值,即:如果给定的(或指定的)字符是 Java 或 Unicode 标识符的一部分的可忽略控制字符,则返回 true。否则,此方法返回 false。

示例 1

输出

The first codePoint is an ignorable control character is:  true
The second codePoint is an ignorable control character is: false
The third codePoint is an ignorable control character is:  false

示例 2

输出

The first codePoint is an ignorable control character:  false
The second codePoint  is an ignorable control character: false

Java Character isIdentifierIgnorable() 方法

Character 类的 isIdentifierIgnorable(char ch) 方法通常用于确定指定的字符在 Java 或 Unicode 标识符中是否可以被视为可忽略字符。

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

  • 不具有空白的 ISO 控制字符。
  • 所有具有 FORMAT 通用类别值的字符。

注意:上述方法不能用于处理增补字符。为了支持包括增补字符在内的所有 Unicode 字符,我们可以使用 isIdentifierIgnorable(int codePoint) 方法。

语法

参数

上述方法只需要一个参数

a.) 需要测试的字符。

返回值

isIdentifierIgnorable(char ch) 方法返回一个布尔值,即:如果给定的(或指定的)字符是可忽略的控制字符,并且也是 Java 或 Unicode 标识符的一部分,则返回 true。否则,此方法返回 false。

示例 3

输出

The first character  'A' is an ignorable control character :  false
The second character 'B' is an ignorable control character : false
The third character  'C' is an ignorable control character :  false

示例 4

输出

The first character  '1' is an ignorable control character :  false
The second character '2' is an ignorable control character :  false
The third character  '3' is an ignorable control character :  false

示例 5

输出

Enter the first input of your choice:G
The character 'G' is an ignorable character : false
Enter the second input of your choice:#
The character '#' is an ignorable character : false