
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
- Related Questions & Answers
- Check whether the entered value is a letter or not in Java
- Check whether the entered value is a digit or not in Java
- Check if the value entered is palindrome or not using C language
- C# Program to Check Whether the Entered Number is an Armstrong Number or Not
- Java Program to check whether the entered value is ASCII 7 bit alphabetic
- Check whether the file is hidden or not in Java
- Java Program to check whether the entered value is ASCII 7-bit alphabetic lowercase
- Java Program to check whether the entered value is ASCII 7 bit alphabetic uppercase
- Java Program to check whether the entered value is ASCII 7-bit control character
- Check whether a character is Uppercase or not in Java
- Check whether a character is Lowercase or not in Java
- Check whether a Stack is empty or not in Java
- Check whether a HashSet is empty or not in Java
- Check whether IdentityHashMap empty or not in Java?
- Check whether a NavigableMap empty or not in Java
Advertisements