What is Character.isSpaceChar in Java?

isSpaceChar() is a static method of the Character class in Java used to determine whether a given character is a Unicode space character.

What is a space character?

A space character is only regarded as a space character if the Unicode Standard specifies it as a space character. If the character’s general category type is any of the following, the function returns true:

  1. SPACE_SEPARATOR
  2. LINE_SEPARATOR
  3. PARAGRAPH_SEPARATOR

Syntax

public static boolean isSpaceChar(char ch)

Parameters

char ch: the character to be checked

Return value

isSpaceChar() returns true if the character is a Unicode space character. Otherwise, it returns false.

Overloaded methods

  1. public static boolean isSpaceChar(int codePoint)
  2. public static boolean isSpaceChar(char ch)

Code

In the code below, we pass different Unicode characters to the method to check for the space character:

public class Main {
public static void main(String[] args){
System.out.println(Character.isSpaceChar(' '));
System.out.println(Character.isSpaceChar('\u2029'));
System.out.println(Character.isSpaceChar('\u2028'));
System.out.println(Character.isSpaceChar('\u2056'));
}
}

Free Resources