Java Character isSpaceChar()方法
java.lang.Character.isSpaceChar(char ch) 是java中的一个内置方法,用于确定指定的字符是否是Unicode空间字符。当且仅当一个字符被Unicode标准指定为空格字符时,它才被认为是一个空格字符。
如果该字符的一般类别类型是以下任何一种,该方法将返回真。
- space_separator
- 线条分隔符(LINE_SEPARATOR )
- 段落分隔符(paragraph_separator )
语法
public static boolean isSpaceChar(char ch)
参数: 该函数接受一个强制性参数ch,指定要测试的字符。
返回值: 该方法返回一个布尔值。如果该字符是一个空格字符,该值为True,否则为False。
下面的程序说明了 Character.isSpaceChar() 方法。
程序1 :
// Java program to illustrate the
// Character.isSpaceChar() method
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// create 2 char primitives c1, c2 and assign values
char c1 = '$', c2 = '\u2025';
// Function to check if the character is a unicode space or not
boolean bool1 = Character.isSpaceChar(c1);
System.out.println("c1 is a space character? " + bool1);
// Function to check if the character is a unicode space or not
boolean bool2 = Character.isSpaceChar(c2);
System.out.println("c2 is a space character? " + bool2);
}
}
输出:
c1 is a space character? false
c2 is a space character? false
程序2
// Java program to illustrate the
// Character.isSpaceChar() method
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// create 2 char primitives
// c1, c2 and assign values
char c1 = '*', c2 = '\u2028';
// Function to check if the character is a unicode space or not
boolean bool1 = Character.isSpaceChar(c1);
System.out.println("c1 is a space character? " + bool1);
// Function to check if the character is a unicode space or not
boolean bool2 = Character.isSpaceChar(c2);
System.out.println("c2 is a space character? " + bool2);
}
}
输出:
c1 is a space character? false
c2 is a space character? true
**参考资料: **https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isSpaceChar(char)