我遇到了一些代码,其中包含以下内容:
String foo = getvalue("foo");
if (StringUtils.isBlank(foo))
doStuff();
else
doOtherStuff();
这似乎在功能上等同于以下内容:
String foo = getvalue("foo");
if (foo.isEmpty())
doStuff();
else
doOtherStuff();
这两者(org.apache.commons.lang3.StringUtils.isBlank
和java.lang.String.isEmpty
)有什么区别吗?
发布于 2019-09-08 18:06:15
isBlank()和isEmpty()之间唯一的区别是:
StringUtils.isBlank(" ") = true //compared string value has space and considered as blank
StringUtils.isEmpty(" ") = false //compared string value has space and not considered as empty
https://stackoverflow.com/questions/23419087
复制相似问题