if(str != null && !str.isEmpty()) { /* do your stuffs here */ }
if(str != null && !str.isEmpty())
Be 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.
if (myString == null || myString.equals(""))
throw new IllegalArgumentException("empty string");
let str1 = "Hello world!";
let str2 = "";
let str3 = 4;
console.log(str1.length === 0)
console.log(str2.length === 0)
console.log(str3.length === 0)
false
true
false
/* You can use Apache Commons */
StringUtils.isEmpty(str)
/* which checks for empty strings and handles null gracefully. */
/* HINT */
/* the shorter and simler your code, the easier it is to test it */