- if(s != null && s.length() == 0)
- if(("").equals(s))
isEmpty()
:boolean isEmpty()It is just a shorthand for checking length. Of course, if the String is null, you will still get NullPointerException. I don't see much value in adding this convenience method. Instead, I'd like to see a static utility method that also handle null value:
Returns true if, and only if, length() is 0.
public static boolean notEmpty(String s) {
return (s != null && s.length() > 0);
}
Tags: