- 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
How to check if String is empty in Java?
The isEmpty() method of the String class returns true if the length of the current string 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
- Check if a String is empty ("") or null in Java
- How to check if a string is empty in Kotlin?
- Java Program to check if a string is empty or not
- Java Program to Check if a String is Empty or Null
- What is the correct way to check if String is empty in Java?
- Check if a String is whitespace, empty ("") or null in Java
- Check if a String is not empty ("") and not null in Java
- How to Check if an Array is Empty or Not in Java
- Check if a HashMap is empty in Java
- Check if a directory is not empty in Java
- How to check if PSCustomObject is empty in PowerShell?
- Python program to check if the string is empty or not
- Golang program to check if a string is empty or null
- How to check if android editText is empty?
- How to check if String value is Boolean type in java?

Advertisements