Cover Image for String isEmpty()
172 views

String isEmpty()

The isEmpty() method in java is indeed a valid method that belongs to the String class. This method is used to check whether a string is empty, meaning it has a length of 0.

Here’s the correct usage of the isEmpty() method:

String str = "Hello";
boolean isNotEmpty = !str.isEmpty(); // true

String emptyStr = "";
boolean isEmpty = emptyStr.isEmpty(); // true

In the above examples, isNotEmpty will be true because the string “Hello” is not empty, and isEmpty will also be true because the empty string has a length of 0.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS