1public class Null {
2
3 public static boolean isNullOrEmpty(String str) {
4 if(str != null && !str.isEmpty())
5 return false;
6 return true;
7 }
8}
1if(str != null && !str.isEmpty())
2Be sure to use the parts of && in this order, because java will not proceed to evaluate the second part if the first part of && fails, thus ensuring you will not get a null pointer exception from str.isEmpty() if str is null.
1if (myString == null || myString.equals(""))
2 throw new IllegalArgumentException("empty string");