Java Character isWhitespace() Method

The isWhitespace(char ch) method of Character class determines whether the given character(Unicode code point) is a whitespace character or not.

A character in Java can be considered as a whitespace character if one of the following criteria is satisfied:

  • The character is a Unicode space character (either a SPACE_SEPARATOR, or a LINE_SEPARATOR, or a PARAGRAPH_SEPARATOR) but it must not be a non-breaking space.
  • The character must be a HORIZONTAL TABULATION.
  • The character must be a LINE FEED.
  • The character must be a VERTICAL TABULATION.
  • The character must be a FORM FEED.
  • The character must be a CARRIAGE RETURN.
  • The character must be a FILE SEPARATOR.
  • The character must be a GROUP SEPARATOR.
  • The character must be a RECORD SEPARATOR.
  • The character must be a UNIT SEPARATOR.

Syntax

Parameter

The above method requires only one parameter:

a.)The character that needs to be tested.

Return Value

The isWhitespace(char ch) method returns a Boolean value, i.e., true if the given(or specified) character is a Java white space character. Otherwise, this method returns false.

Example 1

Output:

The first character is a white space character :true
The second character is a white space character :false
The third character is a white space character :false

Example 2

Output:

The first character is a white space character :true
The second character is a white space character :true
The third character is a white space character :false

Java Character isWhitespace() Method

The isWhitespace(int codePoint) method of Character class determines whether the given(or specified) character is a whitespace character or not.

A character in Java can be considered as a whitespace character if one of the following criteria is satisfied:

  • The character is a Unicode space character (either a SPACE_SEPARATOR, or a LINE_SEPARATOR, or a PARAGRAPH_SEPARATOR) but it must not be a non-breaking space.
  • The character must be a HORIZONTAL TABULATION.
  • The character must be a LINE FEED.
  • The character must be a VERTICAL TABULATION.
  • The character must be a FORM FEED.
  • The character must be a CARRIAGE RETURN.
  • The character must be a FILE SEPARATOR.
  • The character must be a GROUP SEPARATOR.
  • The character must be a RECORD SEPARATOR.
  • The character must be a UNIT SEPARATOR.

Syntax

Parameter

The above method requires only one parameter:

a.)The codePoint which is the character that needs to be tested.

Return Value

The isWhitespace(int codePoint) method returns a Boolean value, i.e., true if the given(or specified) character is a Java whitespace character. Otherwise, this method returns false.

Example 1

Output:

The codePoint '49' is not a whitespace character.
The codePoint '121' is not a whitespace character.
The codePoint '234' is not a whitespace character.

Example 2

Output:

The codepoint '9' is a whitespace character.
The codepoint '10' is a whitespace character.
The codepoint '13' is a whitespace character.

Example 3

Output:

The first codePoint '9' is a Java space character:true
The first codePoint '121' is a Java space character:false
The first codePoint '245' is a Java space character:false