Home >>Java String Methods >Java String isEmpty() Method
The isEmpty() method in Java String is used to checks whether a string is empty or not.
public boolean isEmpty()
None
Returns- It returns a boolean value:
public class Isemptyexample1
{
public static void main(String[] args)
{
String Name1 = "Hey";
String Name2 = "";
System.out.println(Name1.isEmpty());
System.out.println(Name2.isEmpty());
}
}
public class IsEmptyExample2
{
public static void main(String[] args)
{
String m1="";
String m2="Phptpoint";
if(m1.length()==0 || m1.isEmpty())
System.out.println("m1 String is empty");
else System.out.println("m1");
if(m2.length()==0 || m2.isEmpty())
System.out.println("m2 String is empty");
else System.out.println(m2);
}
}