java.lang.Character isWhitespace(int codePoint)

Description

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

The isWhitespace(int codepoint) method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:

Character.isWhitespace(int codePoint)

Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java isWhitespace() method non statically.

Method Syntax

public static boolean isWhitespace(int codePoint)

Method Argument

Data Type Parameter Description
int codepoint the character (Unicode code point) to be tested.

Method Returns

The isWhitespace(int codePoint) method of Character class returns true if the character is a Java whitespace character; false otherwise.

Compatibility

Requires Java 1.5 and up

Java Character isWhitespace(int codePoint) Example

Below is a simple java example on the usage of isWhitespace(int codePoint) method of Character class.

package com.javatutorialhq.java.examples;

/*
 * This example source code demonstrates the use of 
 * isWhitespace(int codePoint) method of Character class.
 */

public class CharacterIsWhitespaceCodepointExample {

	public static void main(String[] args) {
		
		// initialize a codepoint
		int codepoint = 49;
		
		// check if the codepoint is a whitespace or not
		boolean checkBool = Character.isWhitespace(codepoint);
		// print result
		if(checkBool){
			System.out.print("Codepoint '"+codepoint+"' is a whitespace");
		}
		else{
			System.out.print("Codepoint '"+codepoint+"' is not a whitespace");
		}
		
	}

}

Sample Output

Below is the sample output when you run the above example.

java Character isWhitespace(int codePoint) example output