小言_互联网的博客

Android判断是否为空的工具类

339人阅读  评论(0)
public class EmptyUtils {
    //判空
    public static boolean isEmpty(Object obj){
        if (obj == null)
            return true;
        if (obj instanceof CharSequence)
            return ((CharSequence) obj).length() == 0;
        if (obj instanceof Collection)
            return ((Collection) obj).isEmpty();
        if (obj instanceof Map)
            return ((Map) obj).isEmpty();
        if (obj instanceof Object[]) {
            Object[] object = (Object[]) obj;
            if (object.length == 0) {
                return true;
            }
            boolean empty = true;
            for (int i = 0; i < object.length; i++) {
                if (!isEmpty(object[i])) {
                    empty = false;
                    break;
                }
            }
            return empty;
        }
        return false;
    }
    public static boolean isNotEmpty(Object obj){
        return !isEmpty(obj);
    }
       private boolean validPropertyEmpty(Object ...args) {
            for (int i = 0; i < args.length; i++) {
                if(EmptyUtils.isEmpty(args[i])){
                    return true;
                }
            }
            return false;
        }

}

转载:https://blog.csdn.net/zanxuelong/article/details/100857985
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场