Possible Duplicate:
Why is there no String.Empty in java?
Is there a JDK constant for an empty String, something like String.EMPTY, equaling ""? I can't seem to find it. I would prefer using that rather than "".
Thanks
No, there isn't. But since the entire world (well, almost) uses Jakarta Commons-Lang, you can, too. Use StringUtils.EMPTY
: http://commons.apache.org/lang/api-2.6/org/apache/commons/lang/StringUtils.html#EMPTY
What's wrong with ""
? It behaves like a constant, it's taken from the string pool and it's really short to write, much shorter than String.EMPTY
.
Also, if what you need is to test if a string is empty, just do this:
myString.isEmpty();
UPDATE
If the string can be null, better use either isEmpty()
or isNotBlank()
from Apache Common's StringUtils class.
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