这肯定有人问过,但是 Googling doesn't find it 。在任何标准 java 库(包括 apache/google/...)中,是否有用于 Strings
的静态 isNullOrEmpty()
方法?
最佳答案
-
StringUtils.isEmpty(str)
或StringUtils.isNotEmpty(str)
-
StringUtils.isBlank(str)
或StringUtils.isNotBlank(str)
来自 Apache commons-lang .
empty
和 blank
的区别是:由空格组成的字符串是 blank
但不是 empty
.
如果可能的话,我通常更喜欢使用 apache-commons,而不是编写自己的实用程序方法,尽管这对于像这样的简单方法也是合理的。
关于java - Java中的字符串isNullOrEmpty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2272169/