Java Array Empty Check isEmptyOrNull(Object[] array)

Here you can find the source of isEmptyOrNull(Object[] array)

Description

is Empty Or Null

License

Open Source License

Declaration

public static boolean isEmptyOrNull(Object[] array) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  w ww.  ja  va2  s  .  c  o  m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static boolean isEmptyOrNull(Object obj) {
        return (null == obj);
    }

    public static boolean isEmptyOrNull(String str) {
        return (null == str || str.length() == 0);
    }

    public static boolean isEmptyOrNull(Object[] array) {
        return (null == array || array.length == 0);
    }

    public static boolean isEmptyOrNull(Object[] array, boolean checkItems) {
        if (isEmptyOrNull(array)) {
            return true;
        }
        for (Object anArray : array) {
            if (!isEmptyOrNull(anArray)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isEmptyOrNull(Collection<?> collection) {
        return (null == collection || collection.size() == 0);
    }

    public static boolean isEmptyOrNull(Collection<?> collection, boolean checkItems) {
        if (isEmptyOrNull(collection)) {
            return true;
        }
        Iterator<?> i = collection.iterator();
        while (i.hasNext()) {
            if (!isEmptyOrNull(i.next())) {
                return false;
            }
        }
        return true;
    }

    public static boolean isEmptyOrNull(byte[] array) {
        return (null == array || array.length == 0);
    }
}

Related

  1. isEmpty(T[] array)
  2. isEmpty(T[] array)
  3. isEmpty(T[] array)
  4. isEmpty(T[] array)
  5. isEmpty(T[] array)
  6. isEmptyOrNull(Object[] array)
  7. isNonEmpty(Object[] array)
  8. isNotEmpty(boolean[] values)
  9. isNotEmpty(Object[] array)