The
java.lang.Character.isWhitespace() is an inbuilt method in a java that determines if the specified character (Unicode code point) is white space according to Java. A character is a Java whitespace character if and only if it satisfies one of the following criteria:
- It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').
- It is '\t', U+0009 HORIZONTAL TABULATION.
- It is '\n', U+000A LINE FEED.
- It is '\u000B', U+000B VERTICAL TABULATION.
- It is '\f', U+000C FORM FEED.
- It is '\r', U+000D CARRIAGE RETURN.
- It is '\u001C', U+001C FILE SEPARATOR.
- It is '\u001D', U+001D GROUP SEPARATOR.
- It is '\u001E', U+001E RECORD SEPARATOR.
- It is '\u001F', U+001F UNIT SEPARATOR.
Syntax:
public static boolean isWhitespace(datatype character)
Parameters: The function accepts one mandatory parameter
character. This parameter can be of datatype int or char. It specifies the character to be tested.
Return value: This method returns true if the character is a Java whitespace character, false otherwise.
Below programs illustrate the Character.isWhitespace(char ch) method:
Program 1:
Output:
c1 is a Java whitespace character is false
c2 is a Java whitespace character is true
Program 2:
Output:
c1 is a Java whitespace character is false
c2 is a Java whitespace character is true
Program 3: When the parameter is of type
int.
Output:
c1 represents Java whitespace character is false
c2 represents Java whitespace character is false
Program 4: When the parameter is of type
int.