Java Character isDefined() 方法

6 Nov 2024 | 3 分钟阅读

Character 类的 isDefined(char ch) 方法通常用于确定该字符是否在 Unicode 中已定义。

当且仅当满足以下两个条件之一(或都为 true)时,该字符在 Unicode 中才被定义:

  • 该字符必须在 UnicodeData 文件中有条目。
  • 该字符的范围必须由 UnicodeData 文件定义。

语法

参数

上述方法只需要一个参数

a.) 需要测试的字符。

返回值

isDefined(char ch) 方法返回一个布尔值,即:如果给定的(或指定的)字符在 Unicode 中具有已定义的含义,则返回 true。否则,返回 false。

示例 1

输出

The meaning for the character @ is defined as:  true
The meaning for the character * is defined as:  true
The meaning for the character & is defined as:  true

示例 2

输出

Enter a character:   $
The user input '$' is defined in the Unicode
Enter the second character:   )
The user input ')' is defined in the Unicode

示例 3

输出

1 is defined in the Unicode character set: true
2 is defined in the Unicode character set: true
3 is defined in the Unicode character set: true
4 is defined in the Unicode character set: true
5 is defined in the Unicode character set: true