Java Character isSpaceChar() 方法

6 Nov 2024 | 3 分钟阅读

Character 类的 isSpaceChar(char ch) 方法用于确定给定的(或指定的)字符是否为 Unicode 空格字符。

如果字符被 Unicode 标准指定为空格字符,则认为给定的(或指定的)字符为空格字符。

上述方法在字符的通用类别属于以下任一类别时返回 true:

  • SPACE_SEPARATOR
  • LINE_SEPARATOR
  • PARAGRAPH_SEPARATOR

语法

参数

ch:需要测试的字符。

返回值

isSpaceChar(char ch) 方法返回一个布尔值,即如果给定的(或指定的)字符是空格字符,则返回 true。否则,该方法返回 false。

示例 1

输出

The first character is a space character: true
The second character is a space character: true
The second character is a space character: true

示例 2

输出

The first character is a space character: false
The first character is a space character: false

示例 3

输出

Enter the first input:_
The character '_' is not a space character.
Enter the second input:}
The character '}' is a space character.
Enter the third input:*
The character '*' is not a space character.