Signup/Sign In
LAST UPDATED: NOVEMBER 24, 2020

Java Character isSpaceChar(int codePoint) Method

Java isSpaceChar(int codePoint) 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 also handles 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(int codePoint)

Parameters:

The parameter passed is the Unicode codepoint 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)
	{  
		int cp1 = 32;  
		int cp2 = 60;  
		int cp3 = 119;  
		int cp4 = 93;   
		int cp5 = 1232;  

		boolean b1 = Character.isSpaceChar(cp1);  
		boolean b2 = Character.isSpaceChar(cp2);  
		boolean b3 = Character.isSpaceChar(cp3);  
		boolean b4 = Character.isSpaceChar(cp4);  
		boolean b5 = Character.isSpaceChar(cp5);  

		System.out.println((char)cp1 +" is a space character??:  "+b1);  
		System.out.println((char)cp2 +" is a space character??:  "+b2);  
		System.out.println((char)cp3 +" is a space character??:  "+b3);  
		System.out.println((char)cp4 +" is a space character??:  "+b4);  
		System.out.println((char)cp5 +" is a space character??:  "+b5);  
	}  
} 


is a space character??: true
< is a space character??: false
w is a space character??: false
] is a space character??: false
? is a space character??: false

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 Unicode character: ");  
			Scanner sc = new Scanner(System.in);        
			int cp = sc.nextInt(); 
			boolean b = Character.isSpaceChar(cp);
			System.out.println((char)cp + " is a space character?: "+b);
		}
		catch(Exception e)
		{
			System.out.println("Invalid Input!!");
		}
	}
}


Enter the Unicode character: 32
is a space character?: true
******************************************
Enter the Unicode character: 77
M 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.



About the author:
A Computer Science and Engineering Graduate(2016-2020) from JSSATE Noida. JAVA is Love. Sincerely Followed Sachin Tendulkar as a child, M S Dhoni as a teenager, and Virat Kohli as an adult.