- Trending Categories
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
Checking for Null or Empty or White Space Only String in Java.
We can verify whether the given string is empty using the isEmpty() method of the String class. This method returns true only if length() is 0.
Example
import java.lang.*; public class StringDemo { public static void main(String[] args) { String str = "tutorialspoint"; // prints length of string System.out.println("length of string = " + str.length()); // checks if the string is empty or not System.out.println("is this string empty? = " + str.isEmpty()); } }
Output
length of string = 14 is this string empty? = false
- Related Articles
- Checking for Null or Empty in Java.
- Check if a String is empty ("") or null in Java
- Check if a String is whitespace, empty ("") or null in Java
- Java Program to Check if a String is Empty or Null
- How to test String is null or empty?
- Check if the String has only unicode digits or space in Java
- Java program to find whether the given string is empty or null
- Which one is better in MySQL - NULL or empty string?
- Check if the String contains only unicode letters, digits or space in Java
- Set a custom value for NULL or empty values in MySQL
- Check for NULL or empty variable in a MySQL stored procedure
- Which one is better to insert NULL or empty string in MySQL?
- Golang program to check if a string is empty or null
- Check whether a field is empty or null in MySQL?
- Finding the only even or the only odd number in a string of space separated numbers in JavaScript

Advertisements