Java.lang.Character.isWhitespace() Method



The java.lang.Character.isWhitespace(char ch) determines if the specified character 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.


Following is the declaration for java.lang.Character.isWhitespace() method

public static boolean isWhitespace(char ch)


  • ch - the character to be tested

Return Value

This method returns true if the character is a Java whitespace character, false otherwise.


  • NA


The following example shows the usage of lang.Character.isWhitespace() method.

package com.tutorialspoint;

import java.lang.*;

public class CharacterDemo {

   public static void main(String[] args) {

      // create 2 char primitives ch1, ch2
      char ch1, ch2;

      // assign values to ch1, ch2
      ch1 = ' ';
      ch2 = '\f';

      // create 2 boolean primitives b1, b2
      boolean b1, b2;

       *  check if ch1, ch2 are whitespace characters and 
       *  assign results to b1, b2
      b1 = Character.isWhitespace(ch1);
      b2 = Character.isWhitespace(ch2);

      String str1 = "ch1 is a Java whitespace character is " + b1;
      String str2 = "ch2 is a Java whitespace character is " + b2;

      // print b1, b2 values
      System.out.println( str1 );
      System.out.println( str2 );

Let us compile and run the above program, this will produce the following result:

ch1 is a Java whitespace character is true
ch2 is a Java whitespace character is true