![](/img/trans.png)
[英]Apache's StringUtils.isBlank(str) vs. Guava's Strings.isNullOrEmpty(str): Should you routinely check for whitespace?
[英]Equivalent of Guava's Strings.isNullOrEmpty() for Long, Integer, etc
在诸如Java盒装数字基元类型的番石榴等实用程序库中是否有类似.isNullOrZero()的东西?
如果Integer,Long不为null
,则不能为null
; 在这种情况下可以为零。 因此,对于Integer或Long,您可以编写如下内容-
public static boolean isNullOrZero( final Object obj) {
if(null == obj) return true;
if( obj instanceof Integer ){
Integer i = (Integer) obj;
return (i == 0);
}
if( obj instanceof Long ){
Long l = (Long) obj;
return (l == 0);
}
}
对于Collection,如果它不为null,则可以为空。 然后,您可以像这样编写自己的isNullOrEmpty()
方法-
public static boolean isNullOrEmpty( final Collection< ? > collection ) {
return (collection == null || collection.isEmpty() );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.