In this section, we will learn what the Character isWhitespace() method is and how to use it in Java.
What is Java Character isWhitespace() Method?
The `isWhitespace()` method is used to see if the target character is a white-space like `tab` or `newline` or `space` etc.
Java isWhitespace() Method Syntax:
static boolean isWhitespace(char ch)
isWhitespace() Method Parameters:
The method takes one argument and that is the character we want to check and see if it’s a white space.
isWhitespace() Method Return Value:
The return value of this method is a boolean.
If the target character was a white space, then the result will be true otherwise, the value false will return.
Example: using Character isWhitespace() method
public class Simple { public static void main(String args[]) { char character = '\n'; System.out.println(Character.isWhitespace(character)); } }
Output: true
Example: checking for white space characters in Java
public class Simple { public static void main(String args[]) { char character = '\t'; System.out.println(Character.isWhitespace(character)); } }
Output: true