You can try isEmpty()
if(str != null && !str.isEmpty())
Be certain to use the parts of && in this sequence, because java will not continue to evaluate the second part if the first part of && deserts, thus assuring you won't get a null pointer deviation of str.isEmpty() if str is null.
Beware, it's only likely since Java SE 1.6. You have to examine str.length() == 0 on earlier versions.
To neglect whitespace as well:
if(str != null && !str.trim().isEmpty())
(From Java 11 str.trim().isEmpty() can be reduced to str.isBlank() which will also test for other Unicode white spaces)
Encased in a handy function:
public static boolean empty( closing String s ) {
// it's Null-safe and also short-circuit evaluation.
return s == null || s.trim().isEmpty();
}
Becomes:
if( !empty( str ) )