[英]Equivalent of Guava's Strings.isNullOrEmpty() for Long, Integer, etc
在诸如Java盒装数字基元类型的番石榴等实用程序库中是否有类似.isNullOrZero()的东西?
A Integer, Long can not be empty if it is not null
; 如果Integer,Long不为
null
,则不能为null
; it can be zero in this case. 在这种情况下可以为零。 So for Integer or Long you can write something like this -
因此,对于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);
}
}
For Collection, if it is not null then it can be empty. 对于Collection,如果它不为null,则可以为空。 Then you can write your own
isNullOrEmpty()
method like this - 然后,您可以像这样编写自己的
isNullOrEmpty()
方法-
public static boolean isNullOrEmpty( final Collection< ? > collection ) {
return (collection == null || collection.isEmpty() );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.