Trusted answers to developer questions

What is Character.isWhitespace() in Java?

Free System Design Interview Course

Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2024 with this popular free course.

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(' '));
}
}

RELATED TAGS

java
Did you find this helpful?