Java Character isWhitespace() Method
Example
Check if characters are whitespace:
public class Main {
public static void main(String[] args) {
System.out.println(Character.isWhitespace(' '));
System.out.println(Character.isWhitespace('\t'));
System.out.println(Character.isWhitespace('\n'));
System.out.println(Character.isWhitespace('A'));
}
}
Definition and Usage
The isWhitespace() method checks if a character is whitespace (a character that shows as empty space).
Whitespace characters are the space ' ', the tab '\t', the new line '\n' and a few others.
Syntax
One of the following:
public static boolean isWhitespace(char ch)
public static boolean isWhitespace(int codePoint)
Most programs use the first version, with a char. The second version takes the character as a code point (the number that Unicode gives each character), as an int.
Parameter Values
| Parameter | Description |
|---|---|
| ch | Required. The character to check. |
| codePoint | Required. The code point of the character to check. |
Technical Details
| Returns: | true if the character is whitespace, otherwise false. |
|---|
Related Pages
❮ Character Methods