How to check whether the given string is empty - Java Language Basics

Java examples for Language Basics:String

Description

How to check whether the given string is empty

Demo Code



public class Main {
        public static void main(String args[]){
               //  w  w w .  j  av a2  s  .  c  om
                String str1 = "";
                String str2 = null;
                String str3 = "Hello World";
               
                System.out.println("Is String 1 empty? :" + str1.isEmpty());
               
                System.out.println("Is String 3 empty? :" + str3.isEmpty());
               
        }
}

Result


Related Tutorials