Java中的字符.isSpaceChar()方法
Java.lang。 字符.isSpaceChar(char ch)是Java中的一个内置方法,用于确定指定字符是否为 Unicode 空格字符。当且仅当 Unicode 标准将字符字符,该字符才被视为空格字符。
如果角色的一般类别类型是以下任何一种,则此方法返回 true ?
- SPACE_SEPARATOR
- LINE_SEPARATOR
- PARAGRAPH_SEPARATOR
句法:
public static boolean isSpaceChar(char ch)
参数:该函数接受一个强制参数ch ,它指定要测试的字符。
返回值:此方法返回一个布尔值。如果字符是空格字符,则值为True ,否则为False 。
下面的程序说明了字符.isSpaceChar()方法:
方案一:
// 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
方案二:
// 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: Java/lang/ 字符.html#isSpaceChar(char)