Java .isEmpty()

Anonymous contributor's avatar
Anonymous contributor
Published Mar 4, 2023
Contribute to Docs

The .isEmpty() method returns true if a string has no content. It returns false if the string has content.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours

Syntax

string.isEmpty();
  • string: The string to be checked for content.

Example 1

The example below applies the .isEmpty() method to the strings drink and food:

// isStringEmpty.java
class isStringEmpty {
public static void main(String[] args) {
String drink = "lemonade";
String food = "";
System.out.println(drink.isEmpty());
System.out.println(food.isEmpty());
}
}

This will print the following output:

false
true

All contributors

Contribute to Docs

Learn Java on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours