Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

isEmpty()

Example

Determine whether a string is empty or not.

String myStr1 = "Hello";
String myStr2 = "";
System.out.println(myStr1.isEmpty());
System.out.println(myStr2.isEmpty());

Definition and Usage

The isEmpty() method determines if a string is empty or not.

It returns true if the string’s length is 0, and false otherwise.

Syntax

public boolean isEmpty()

Parameters

None.

Technical Details

Return

A boolean value is returned:

 

  •            true indicates that the string is empty (length() is 0).
  •            false indicates that the string is not empty.