3 Ways to check if String is null or empty in Java
if(stirng != null && !string.isEmpty())
{
System.out.println("String is not null and not empty");
}
====================================================================
if(stirng != null && string.length() > 0)
{
System.out.println("String is not null and not empty");
}
======================================================================
if(stirng != null && string.trim().length() > 0)
{
System.out.println("String is not null and not empty");
}
if(stirng != null && !string.isEmpty())
{
System.out.println("String is not null and not empty");
}
====================================================================
if(stirng != null && string.length() > 0)
{
System.out.println("String is not null and not empty");
}
======================================================================
if(stirng != null && string.trim().length() > 0)
{
System.out.println("String is not null and not empty");
}
No comments:
Post a Comment