如题所述
如数组为a,则a.length==0表示a就是空数组
温馨提示:答案为网友推荐,仅供参考
第1个回答 2016-03-22
public static boolean isEmpty(Object obj) {
if (obj == null) {
return true;
}
if (obj instanceof String && obj.toString().trim().length() == 0) {
return true;
}
if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
return true;
}
if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
return true;
}
if (obj instanceof Map && ((Map) obj).isEmpty()) {
return true;
}
return false;
}
if (obj == null) {
return true;
}
if (obj instanceof String && obj.toString().trim().length() == 0) {
return true;
}
if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
return true;
}
if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
return true;
}
if (obj instanceof Map && ((Map) obj).isEmpty()) {
return true;
}
return false;
}
第2个回答 2015-04-21
直接判断数组的长度是不是0,是0就是空的,否则反之
第3个回答 2015-04-21
判断:
if( 数组 !=null && 数组.length ){
System.out.println("你的数组不为空!");
}
if( 数组 !=null && 数组.length ){
System.out.println("你的数组不为空!");
}
第4个回答 2015-04-21
判断一下:
a != null && a.length != 0
a != null && a.length != 0