当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Character.isSpaceChar()用法及代码示例


java.lang.Character.isSpaceChar(char ch)是java中的一个内置方法,该方法确定指定字符是否为Unicode空格字符。当且仅当Unicode标准将其指定为空格字符时,才将其视为空格字符。

如果角色的常规类别类型是以下任意一种,则此方法返回true?

  • 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)



相关用法


注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 Character.isSpaceChar() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。