Write a program to check if a string variable is empty or not

Method to check if a string is empty or not: String.isEmpty();

public class Main {
    public static void main(String[] args) {
       String string1="Hello Java";
       String string2="";
       boolean str1=string1.isEmpty(); //expected: should be false
       boolean str2=string2.isEmpty(); //expected: should be true

       System.out.println(str1);
       System.out.println(str2);

    }

}
Output:
false
true
about author

admin

salmansrabon@gmail.com

If you like my post or If you have any queries, do not hesitate to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *