'Character.isWhitespace' method takes a character and return true if the given character is whitespace, else false.
package com.sample.app;
public class App {
private static void printWhitSpace(char charz) {
if(Character.isWhitespace(charz)) {
System.out.println("'" + charz + "' is a whitespace");
}else {
System.out.println("'" + charz + "' is not a whitespace");
}
}
public static void main(String args[]) {
printWhitSpace('a');
printWhitSpace('\t');
printWhitSpace(' ');
printWhitSpace('@');
}
}
Output
'a' is not a whitespace
' ' is a whitespace
' ' is a whitespace
'@' is not a whitespace
You may
like
No comments:
Post a Comment