
- 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
How to test String is null or empty?
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 Questions & Answers
- Java Program to Check if a String is Empty or Null
- Which one is better in MySQL - NULL or empty string?
- Java program to find whether the given string is empty or null
- Which one is better to insert NULL or empty string in MySQL?
- Check if a String is empty ("") or null in Java
- How to check if field is null or empty in MySQL?
- Checking for Null or Empty or White Space Only String in Java.
- Check if a String is whitespace, empty ("") or null in Java
- How to update empty string to NULL in MySQL?
- Check whether a field is empty or null in MySQL?
- Checking for Null or Empty in Java.
- How do I check if a column is empty or null in MySQL?
- MongoDB query which represents not equal to null or empty?
- How to test if a URL string is absolute or relative - JavaScript?
- How it is possible to insert a zero or an empty string into a MySQL column which is defined as NOT NULL?
Advertisements