I have a setter method.
Then when another (say generate) method is run, I need to check the value of my fields. So in the case of String property, I need to know if
Add maven dependency for com.google.guava
Then in your code:
import com.google.common.base.Strings;
if(!Strings.isNullOrEmpty(s)) {
// Do stuff here
}
if(s != null && !s.isEmpty()){
// this will work even if 's' is NULL
}
try this
if(s){
}
use org.apache.commons.lang.StringUtils, the method StringUtils.isNotBlank check both nullity and emptiness.
Commons library, StringUtils.isBlank() or StringUtils.isEmtpy().
isEmpty is equivalent to
s == null || s.length() == 0
isBlank is equivalent to
s == null || s.trim().length() == 0
In the jakarta commons there is a StringUtils.isEmpty(String).