Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Character.isWhitespace(char) and Character.isSpaceChar(char)

Tags:

java

Both of them returns true if it is empty char / white space or else it returns false. My question is why java has both the methods as they are doing the same thing

like image 720
karthik vishnu kumar Avatar asked Sep 12 '16 13:09

karthik vishnu kumar


1 Answers

Method isSpaceChar(char) is only for checking unicode space character (SPACE_SEPARATOR,LINE_SEPARATOR, PARAGRAPH_SEPARATOR) while method isWhiteSpace(char) is for space as well as other white space characters like tab,carriage return etc

char ch='\t';
System.out.println(Character.isWhitespace(ch));
System.out.println( Character.isSpaceChar(ch));

It outputs

true
false
like image 50
Loki Avatar answered Sep 24 '22 15:09

Loki