java判断对象或者对象数组是否为空的类

  • Post author:
  • Post category:java


判断对象或者对象数组是否为空。

package com.kinth.common.util;

import java.util.List;
import java.util.Map;

public class ParamValidator {

    public static boolean isNullOrEmptyObject(Object obj) {
        return obj == null || obj.toString().trim().isEmpty();
    }

    public static boolean isNullOrEmptyArray(Object[] array) {
        if(array == null) {
            return true;
        }

        if(array.length ==0) {
            return true;
        }

        boolean eachItemIsNull = true;
        for(Object item:array) {
            if(item != null) {
                eachItemIsNull = false;
            }
        }
        return eachItemIsNull;
    }

    public static boolean isNullOrEmptyList(List<?> list) {
        if(list == null) {
            return true;
        }

        if(list.isEmpty()) {
            return true;
        }

        boolean eachItemIsNull = true;
        for(Object item:list) {
            if(item != null) {
                eachItemIsNull = false;
            }
        }
        return eachItemIsNull;
    }

    public static boolean isNullOrEmptyMap(Map<?,?> map) {
        if(map == null) {
            return true;
        }

        if(map.isEmpty()) {
            return true;
        }

        return false;
    }
}



版权声明:本文为qq_29606255原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。