java.lang.Character.isWhitespace(int codePoint) 確定指定字元(Unicode程式碼點)是根據Java的空白。字元是一個Java空白字元,當且僅當它滿足下列條件之一:
它是一個Unicode空格字元 (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) 但不也是非間斷空格 ('u00A0', 'u2007', 'u202F').
它是 ' ', U+0009 HORIZONTAL TABULATION.
它是 ' ', U+000A LINE FEED.
它是 'u000B', U+000B VERTICAL TABULATION.
它是 'f', U+000C FORM FEED.
它是 '', U+000D CARRIAGE RETURN.
它是 'u001C', U+001C FILE SEPARATOR.
它是 'u001D', U+001D GROUP SEPARATOR.
它是 'u001E', U+001E RECORD SEPARATOR.
它是 'u001F', U+001F UNIT SEPARATOR.
以下是java.lang.Character.isWhitespace()方法的宣告
public static boolean isWhitespace(int codePoint)
codePoint - 要進行測試的字元(Unicode程式碼點)
如果字元是一個Java空白字元此方法返回true,否則返回false。
NA
下面的例子顯示了lang.Character.isWhitespace()方法的使用。
package com.yiibai; 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 = 0x001c; // represents FILE SEPARATOR cp2 = 0x0abc; // create 2 boolean primitives b1, b2 boolean b1, b2; /** * check if cp1, cp2 represent whitespace characters * and assign results to b1, b2 */ b1 = Character.isWhitespace(cp1); b2 = Character.isWhitespace(cp2); String str1 = "cp1 represents Java whitespace character is " + b1; String str2 = "cp2 represents Java whitespace character is " + b2; // print b1, b2 values System.out.println( str1 ); System.out.println( str2 ); } }
讓我們來編譯和執行上面的程式,這將產生以下結果:
cp1 represents Java whitespace character is true cp2 represents Java whitespace character is false