Java Character isSpaceChar(char ch) Method

Java isSpaceChar(char ch) method is a part of Character class. This method is used to check whether the specified character is a Unicode space character or not.

This method does not handle supplementary characters. A character is considered to be a space character if and only if it is specified to be a space character by the Unicode Standard. This method returns true if the character's general category type is any of the following:

  • SPACE_SEPARATOR
  • LINE_SEPARATOR
  • PARAGRAPH_SEPARATOR

Syntax:

public static boolean isSpaceChar(char ch)

Parameters:

The parameter passed is the character to be checked whether it is a space character or not.

Returns:

Returns the boolean value true if the specified character is a space character else return false.

Example 1:

Here, the characters are checked whether they are space characters or not.

public class StudyTonight
{  
	public static void main(String[] args)
	{  
		char ch1 = 'h';  
		char ch2 = '\u2028';  
		char ch3 = '\u2078';  
		char ch4  = '0';   
		char ch5  = ' ';  

		boolean b1 = Character.isSpaceChar(ch1);  
		boolean b2 = Character.isSpaceChar(ch2);  
		boolean b3 = Character.isSpaceChar(ch3);  
		boolean b4 = Character.isSpaceChar(ch4);  
		boolean b5 = Character.isSpaceChar(ch5);  

		System.out.println(ch1 +" is space character??:  "+b1);  
		System.out.println(ch2 +" is space character??:  "+b2);  
		System.out.println(ch3 +" is space character??:  "+b3);  
		System.out.println(ch4 +" is space character?? : "+b4);  
		System.out.println(ch5 +" is space character??:  "+b5);  
	}  
} 


h is space character??: false
? is space character??: true
? is space character??: false
0 is space character?? : false
is space character??: true

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.

import java.util.Scanner; 
public class StudyTonight
{  
	public static void main(String[] args)
	{  
		try
		{
			System.out.print("Enter the character: ");  
			Scanner sc = new Scanner(System.in);         
			char ch = sc.next().charAt(0);  
			boolean b = Character.isSpaceChar(ch);
			System.out.println(ch + " is a space character?: "+b);

		}
		catch(Exception e)
		{
			System.out.println("Invalid Input!!");
		}
	}  
}


Enter the character: u
u is a space character?: false
***********************************
Enter the character: 1
1 is a space character?: false

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.