判断对象是否为空 、 工具类

时间:2016-09-21 11:35:07   收藏:0   阅读:1008

/**
     * 判断对象是否为空
     */
    public static boolean isEmpty(Object obj) {
        if (obj == null)
            return true;

        if (obj instanceof String)
            return StringUtils.isEmptyOrWhitespaceOnly((String) obj);
        if (obj instanceof Collection && ((Collection<?>) obj).isEmpty())
            return true;
        if (obj.getClass().isArray() && Array.getLength(obj) == 0)
            return true;
        if (obj instanceof Map && ((Map<?, ?>) obj).isEmpty())
            return true;

        return false;
    }

原文:http://www.cnblogs.com/xjbBill/p/5891946.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!