本文介绍了StringUtils.isBlank()vs String.isEmpty()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一些代码如下:
I ran into some code that has the following:
String foo = getvalue("foo");
if (StringUtils.isBlank(foo))
doStuff();
else
doOtherStuff();
这看起来在功能上等同于以下内容:
This appears to be functionally equivalent to the following:
String foo = getvalue("foo");
if (foo.isEmpty())
doStuff();
else
doOtherStuff();
两者之间是否存在差异( org.apache.commons.lang3。 StringUtils.isBlank
和 java.lang.String.isEmpty
)?
Is a difference between the two (org.apache.commons.lang3.StringUtils.isBlank
and java.lang.String.isEmpty
)?
推荐答案
检查字符串的每个字符是否为空格字符(或者字符串为空或者是它是空的)。这与检查字符串是否为空完全不同。
StringUtils.isBlank()
checks that each character of the string is a whitespace character (or that the string is empty or that it's null). This is totally different than just checking if the string is empty.
来自链接文档:
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
这篇关于StringUtils.isBlank()vs String.isEmpty()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!