Java Collection Empty isNullOrEmpty(final Collection value)

Here you can find the source of isNullOrEmpty(final Collection value)

Description

Tests given value to see if it is empty.

License

Open Source License

Parameter

Parameter Description
value Value to test.

Return

True if empty.

Declaration

public static boolean isNullOrEmpty(final Collection<?> value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

public class Main {
    /**/*from   w w  w . j  a va2  s.  com*/
     * Tests given value to see if it is empty.
     * 
     * @param value
     *            Value to test.
     * @return True if empty.
     */
    public static boolean isNullOrEmpty(final Collection<?> value) {

        return isNull(value) || isEmpty(value);
    }

    /**
     * Tests given value to see if it is empty.
     * 
     * @param value
     *            Value to test.
     * @return True if empty.
     */
    public static boolean isNullOrEmpty(final Object[] value) {

        return isNull(value) || isEmpty(value);
    }

    /**
     * Tests given value to see if it is empty.
     * 
     * @param value
     *            Value to test.
     * @return True if empty.
     */
    public static boolean isNullOrEmpty(final String value) {

        return isNull(value) || isEmpty(value);
    }

    /**
     * Method to check for null. This is here just for completeness.
     * 
     * @param arg
     *            Any object.
     * @return True if null false if not.
     */
    public static boolean isNull(final Object arg) {

        return null == arg;
    }

    /**
     * Tests given value to see if it is empty.
     * 
     * @param value
     *            Value to test. Does not check to see if it is null.
     * @return True if empty.
     */
    public static boolean isEmpty(final Collection<?> value) {

        return 0 == value.size();
    }

    /**
     * Tests given value to see if it is empty.
     * 
     * @param value
     *            Value to test. Does not check to see if it is null.
     * @return True if empty.
     */
    public static boolean isEmpty(final Object[] value) {

        return 0 == value.length;
    }

    /**
     * Tests given value to see if it is empty.
     * 
     * @param value
     *            Value to test. Does not check to see if it is null.
     * @return True if empty.
     */
    public static boolean isEmpty(final String value) {

        return 0 == value.length();
    }
}

Related

  1. isNullOrEmpty(Collection obj)
  2. isNullOrEmpty(Collection s)
  3. isNullOrEmpty(Collection values)
  4. isNullOrEmpty(final Collection c)
  5. isNullOrEmpty(final Collection collection)
  6. isNullOrEmpty(final Collection collection)
  7. isNullOrEmpty(T collection)
  8. nullOrEmpty(Collection coll)
  9. nullOrEmpty(Collection tested)