Home » Java programming language

Java Character class isWhitespace() method with example

Character class isWhitespace() method: Here, we are going to learn about the isWhitespace() method of Character class with its syntax and example.
Submitted by Preeti Jain, on October 26, 2019

Character class isWhitespace() method

  • isWhitespace() method is available in java.lang package.
  • isWhitespace() method is used to check whether the given char value is whitespace or not but it includes other things in whitespace (i.e. Tab, Space, Newline).
  • isWhitespace() method does not throw an exception at the time of checking the given char value is whitespace or not.


    public boolean isWhitespace (Char value);


  • Char value – represents the char value to be checked.

Return value:

The return type of this method is boolean, it returns a boolean value based on the following cases,

  • It returns true, if the given char value is whitespace (i.e. space, tab, newline).
  • It returns false, if the given char value is not whitespace (i.e. space, tab, newline).


// Java program to demonstrate the example 
// of boolean isWhitespace (Char value) method of Character class

public class IsWhitespaceOfCharacterClass {
    public static void main(String[] args) {
        // It returns true because the passing character is space   
        boolean result1 = Character.isWhitespace(' ');

        // It returns true because the passing character is a newline  
        boolean result2 = Character.isWhitespace('\n');

        // It returns false because the passing character is not whitespace   
        boolean result3 = Character.isWhitespace('6');

        // Display values of result1 , result2 and result3
        System.out.println("Character.isWhitespace(' '): " + result1);
        System.out.println("Character.isWhitespace('\n'): " + result2);
        System.out.println("Character.isWhitespace('6'): " + result3);


Character.isWhitespace(' '): true
'): true
Character.isWhitespace('6'): false

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.