Java Character isJavaIdentifierPart() 方法

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

isJavaIdentifierPart(char ch) 字符类的方法用于确定给定的(或指定的)字符是否是 Java 标识符的一部分。

如果以下任一条件为真,则给定字符是 Java 标识符的一部分:

  • 该字符是字母。
  • 该字符是货币符号(如 '$')。
  • 该字符是连接标点符号(如 '_')。
  • 该字符是数字。
  • 该字符是数字字母(如罗马数字字符)。
  • 该字符是组合标记。
  • 该字符是非间距标记。
  • isIdentifierIgnorable() 方法对此特定字符返回 true。

语法

参数

ch:需要测试的字符。

返回值

如果给定的(或指定的)字符是 Java 标识符的一部分,则 isJavaIdentifierPart(char ch) 方法返回布尔值 true。否则,该方法返回 false。

示例 1

输出

Enter the first input:&
The character '&' is not a part of Java Identifier.
Enter the second input:A
The character 'A' is a part of Java Identifier.

示例 2

输出

The first character is a part of java identifier:  false
The second character is a part of java identifier: true
The third character is a part of java identifier:  true

Java Character isJavaIdentifierPart() 方法

Character 类中的 isJavaIdentifierPart(int codePoint) 方法用于确定给定的(或指定的)字符是否是 Java 标识符的一部分。

如果以下任一条件为真,则给定字符是 Java 标识符的一部分:

  • 该字符是字母。
  • 该字符是货币符号(如 '$')。
  • 该字符是连接标点符号(如 '_')。
  • 该字符是数字。
  • 该字符是数字字母(如罗马数字字符)。
  • 该字符是组合标记。
  • 该字符是非间距标记。
  • isIdentifierIgnorable() 方法对此特定字符返回 true。

语法

参数

codePoint:需要测试的字符的 codePoint。

返回值

如果给定的(或指定的)字符是 Java 标识符的一部分,则 isJavaIdentifierPart(int codePoint) 方法返回布尔值 true。否则,该方法返回 false。

示例 3

输出

The first codepoint '89' is a part of Java identifier.
The second codepoint '90' is a part of Java identifier.
The third codepoint '110' is a part of Java identifier.

示例 4

输出

The boolean value for the first codePoint is given as: true
The boolean value for the second codePoint is given as: true
The boolean value for the third codePoint is given as: true

示例 5

输出

The boolean value for the first codePoint 'A' is given as: true
The boolean value for the second codePoint 'G' is given as: true
The boolean value for the third codePoint 'k' is given as: true