What is Character.isWhitespace() in Java?

The isWhitespace() function returns true if the character sent as a parameter is whitespace; otherwise, it returns false.

Whitespace includes:

  • space
  • tab (\t)
  • newline (\n)

The following illustration shows a visual representation of the isWhitespace() function.

Visual representation of the isWhitespace() function

Syntax

boolean isWhitespace(char character)

Parameter

The isWhitespace() function takes a character as a parameter.

Return value

The isWhitespace() function returns true if the character sent as a parameter is whitespace and returns false otherwise.

Code

class JAVA {
public static void main( String args[] ) {
//simple letter
System.out.println("Character.isWhitespace('E'):");
System.out.println(Character.isWhitespace('E'));
//tab character
System.out.println("Character.isWhitespace('\t'):");
System.out.println(Character.isWhitespace('\t'));
//space character
System.out.println("Character.isWhitespace(' '):");
System.out.println(Character.isWhitespace(' '));
}
}

Free Resources