Popular Tutorials
Start Learning JavaCertification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Java String isEmpty()
The Java String isEmpty() method checks whether the string is empty or not.
The syntax of the string isEmpty() method is:
string.isEmpty()
Here, string is an object of the String class.
isEmpty() Parameters
The isEmpty() method does not take any parameters.
isEmpty() Return Value
- returns true if the string is empty (length is 0)
- returns false if the string is not empty
Example: Java String isEmpty()
class Main {
public static void main(String[] args) {
String str1 = "Java Programming";
String str2 = "";
System.out.println(str1.isEmpty()); // false
System.out.println(str2.isEmpty()); // true
}
}
Note: A non-initialized string is not an empty string. If you use isEmpty() on a string that is not initialized, you will get an error.
Also Read:
Did you find this article helpful?