Java.lang.Character.isWhitespace() Method



Description

The java.lang.Character.isWhitespace(int codePoint) 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.

Declaration

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

public static boolean isWhitespace(int codePoint)

Parameters

codePoint − the character (Unicode code point) to be tested

Return Value

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

Exception

NA

Example

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 int primitives cp1, cp2
      int cp1, cp2;

      // assign values to cp1, cp2
      cp1 = 0x001c; // represents FILE SEPARATOR
      cp2 = 0x0abc;

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

      /**
       *  check if cp1, cp2 represent whitespace characters 
       *  and assign results to b1, b2
       */
      b1 = Character.isWhitespace(cp1);
      b2 = Character.isWhitespace(cp2);

      String str1 = "cp1 represents Java whitespace character is " + b1;
      String str2 = "cp2 represents 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 −

cp1 represents Java whitespace character is true
cp2 represents Java whitespace character is false
java_lang_character.htm
Advertisements