I render some data based on a condition. The backing method performs a check if a string exists. But I don't know if I can be happy with the compare to null?
public boolean isString(MyClass var) {
return null != var.getMyString();
}
Could it be done better?
I like StringUtils.isNotBlank() from Apache Commons Lang:
StringUtils.isNotBlank(var.getMyString())
It performs extra trim() which is desirable most of the time. If not, use StringUtils.isNotEmpty(). Another advantage: it uses CharSequence so you can pass String, StringBuilder, etc.
You could do:
return var.getMyString() != null && !var.getMyString.isEmpty()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With