Java Collection Empty isNullOrEmpty(Collection col)

Here you can find the source of isNullOrEmpty(Collection col)

Description

Performs a thorough null and empty check.

License

Apache License

Parameter

Parameter Description
col a parameter

Return

asserts that a given collection is null, empty or only consists of null values.

Declaration

public static boolean isNullOrEmpty(Collection<?> col) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**//from w  w w .  ja va 2  s .  c  o  m
     * Performs a thorough null and empty check. This asserts that a given collection is null, empty or only consists of null values.
     *
     * @param col
     * @return asserts that a given collection is null, empty or only consists of null values.
     */
    public static boolean isNullOrEmpty(Collection<?> col) {

        if ((col == null) || col.isEmpty())
            return true;
        else {

            try {

                for (Iterator<?> iterator = col.iterator(); iterator.hasNext();) {

                    if (iterator.next() != null) {
                        return false;
                    }
                }
            } catch (NullPointerException e) { // guard against null during concurrent modifications
                return false;
            }

            return true;
        }
    }
}

Related

  1. isNullOrEmpty(Collection c)
  2. isNullOrEmpty(Collection c)
  3. isNullOrEmpty(Collection coll)
  4. isNullOrEmpty(Collection collection)
  5. isNullOrEmpty(Collection collection)
  6. isNullOrEmpty(Collection collection)
  7. isNullOrEmpty(Collection list)
  8. isNullOrEmpty(Collection obj)
  9. isNullOrEmpty(Collection s)