English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java Flow Control

Java Array

Java Object-Oriented (I)

Java Object-Oriented (II)

Java Object-Oriented (III)

Java Exception Handling

Java List (List)

Java Queue (Queue)

Java Map Collection

Java Set Collection

Java Input Output (I/O)

Java Reader/Writer

Java Other Topics

Java String isEmpty() Method Usage and Example

Java String (String) Methods

The Java String isEmpty() method checks if the string is empty.

The syntax of the string isEmpty() method is:

string.isEmpty()

Here, string is an object of the String class.

isEmpty() Parameter

  • Without any parameters

isEmpty() Return Value

  • If the string is empty (length is 0)Returns true

  • If the string is not emptyReturns false

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:An uninitialized string is not an empty string. If isEmpty() is used on an uninitialized string, an error will be thrown.

Java String (String) Methods