Java Character isSpaceChar()方法

java.lang.Character.isSpaceChar(int codePoint) 确定指定字符(Unicode代码点)是一个Unicode空格字符。字符被认为是当且仅当它被指定为Unicode标准空格字符空格字符。

此方法返回true,如果字符是下列任何一般类别类型:

  • SPACE_SEPARATOR

  • LINE_SEPARATOR

  • PARAGRAPH_SEPARATOR

1 语法

public static boolean isSpaceChar(int codePoint)

2 参数

codePoint:进行测试的字符(Unicode代码点)

3 返回值

如果字符为空格字符此方法返回true,否则返回false。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java Character isSpaceChar()方法
 */
import java.lang.*;

public class CharacterDemo {

   public static void main(String[] args) {

      // create 2 int primitives cp1, cp2
      int cp1, cp2;

      // assign values to cp1, cp2
      cp1 = 0x2029; // PARAGRAPH_SEPARATOR
      cp2 = 0x1010;

      // create 2 boolean primitives b1, b2
      boolean b1, b2;

      /**
       *  check if cp1, cp2 represent space characters
       *  and assign results to b1, b2
       */
      b1 = Character.isSpaceChar(cp1);
      b2 = Character.isSpaceChar(cp2);

      String str1 = "cp1 represents a space character is " + b1;
      String str2 = "cp2 represents a space character is " + b2;

      // print b1, b2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

输出结果为:

cp1 represents a space character is true
cp2 represents a space character is false

 

热门文章

优秀文章