Java - Write code to Check whether a collection is empty or null.

Requirements

Write code to Check whether a collection is empty or null.

Demo

//package com.book2s;
import java.util.Collection;

public class Main {
    public static void main(String[] argv) {
        Collection collection = java.util.Arrays.asList("asdf",
                "book2s.com");
        System.out.println(isEmptyOrNull(collection));
    }/*from w  w  w.  j ava  2  s.  c o  m*/

    /**
     * Checks whether a collection is empty or null.<p>
     * 
     * @param collection a collection 
     * @return true if <code>collection</code> is <code>null</code> or empty.
     */
    public static boolean isEmptyOrNull(Collection<?> collection) {

        return (collection == null) || collection.isEmpty();
    }
}