- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check whether the entered value is whitespace or not in Java
To check whether the entered value is whitespace or not in Java, use the Character.isWhitespace() method.
We have a value to be checked.
char val = ' ';
Now let us use the Character.isWhitespace() method.
if (Character.isWhitespace(val)) { System.out.println("Value is a Whitespace!"); } else { System.out.println("Value is not a Whitespace"); }
Let us see the complete example now to check whether the entered value is whitespace or not in Java.
Example
public class Demo { public static void main(String []args) { char val =' '; System.out.println("Value: "+val); if (Character.isWhitespace(val)) { System.out.println("Value is a Whitespace!"); } else { System.out.println("Value is not a Whitespace"); } } }
Output
Value: Value is a Whitespace!
Let us see another example.
Example
public class Demo { public static void main(String []args) { char val ='L'; System.out.println("Value: "+val); if (Character.isWhitespace(val)) { System.out.println("Value is a Whitespace!"); }else { System.out.println("Value is not a Whitespace"); } } }
Output
Value: L Value is not a Whitespace
Advertisements