1. 程式人生 > >java判斷物件或者物件陣列是否為空的類

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; } }