1 import java.lang.reflect.Array;
2 import java.util.Collection;
3 import java.util.Map;
4
5 /**
6 * 判断对象是否为空或null
7 */
8 public class ObjectUtils {
9
10 public static boolean isNull(Object obj) {
11 return obj == null;
12 }
13
14 public static boolean isNotNull(Object obj) {
15 return !isNull(obj);
16 }
17
18 public static boolean isEmpty(Object obj) {
19 if (obj == null) return true;
20 else if (obj instanceof CharSequence) return ((CharSequence) obj).length() == 0;
21 else if (obj instanceof Collection) return ((Collection) obj).isEmpty();
22 else if (obj instanceof Map) return ((Map) obj).isEmpty();
23 else if (obj.getClass().isArray()) return Array.getLength(obj) == 0;
24
25 return false;
26 }
27
28 public static boolean isNotEmpty(Object obj) {
29 return !isEmpty(obj);
30 }
31 }