iswhitespace java

h‮:sptt‬//www.lautturi.com
iswhitespace java

To check if a character is a white space character in Java, you can use the Character.isWhitespace() method. This method returns true if the character is a white space character, and false if it is not.

Here is an example of how to use the Character.isWhitespace() method:

char c1 = ' '; // Space character
char c2 = '\t'; // Tab character
char c3 = '\n'; // Newline character
char c4 = 'a'; // Non-white space character

System.out.println(Character.isWhitespace(c1)); // Outputs true
System.out.println(Character.isWhitespace(c2)); // Outputs true
System.out.println(Character.isWhitespace(c3)); // Outputs true
System.out.println(Character.isWhitespace(c4)); // Outputs false

In this example, the Character.isWhitespace() method is called with the characters c1, c2, c3, and c4 as arguments. It returns true for the white space characters c1, c2, and c3, and false for the non-white space character c4.

Note that the Character.isWhitespace() method recognizes the following characters as white space characters: space, tab, newline, carriage return, and form feed.

For more information on the Character.isWhitespace() method and other methods related to character handling in Java, you can refer to the Java documentation or other online resources.

Created Time:2017-11-01 22:29:54  Author:lautturi