Java String Isempty
# Java String isEmpty() Method
[Java String Class](#)
* * *
The isEmpty() method is used to determine whether a string is empty.
### Syntax
public boolean isEmpty()
### Parameters
* None
### Return Value
Returns true if the string is empty, otherwise returns false.
The string calculates its length using the [length()](#) method. If it returns 0, the string is considered empty.
### Example
The following example demonstrates the use of the isEmpty() method:
## Example
public class Main{public static void main(String[]args){String myStr1 = ""; String myStr2 = ""; // Empty string String myStr3 = " "; // Multiple spaces, length() is not 0 System.out.println("Is myStr1 empty: " + myStr1.isEmpty()); System.out.println("Is myStr2 empty: " + myStr2.isEmpty()); System.out.println("myStr3 length: " + myStr3.length()); System.out.println("Is myStr3 empty: " + myStr3.isEmpty()); }}
The output of the above program is:
Is myStr1 empty: false Is myStr2 empty: true myStr3 length: 4 Is myStr3 empty: false
* * Java String Class](#)
YouTip