Java Character isJavaLetterOrDigit() 方法

2024 年 11 月 6 日 | 阅读 2 分钟

Character 类的 isJavaLetterOrDigit(char ch) 方法用于确定给定的(或指定的)字符是否可以作为 Java 标识符的非首字符。

当且仅当满足以下任一条件时,该字符才属于 Java 标识符的一部分:

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

语法

参数

ch:需要测试的字符。

返回值

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

示例 1

输出

The result for the first character is given as:true
The result for the second character is given as:true
The result for the third character is given as:true.

示例 2

输出

The result for the first character is given as:true
The result for the second character is given as:true
The result for the third character is given as:true

示例 3

输出

The result for the first character is given as:true
The result for the second character is given as:false
The result for the third character is given as:true