Check if collection is null or empty. - Java java.util

Java examples for java.util:Collection Operation

Description

Check if collection is null or empty.

Demo Code


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

public class Main {
    public static void main(String[] argv) {
        Collection collection = java.util.Arrays.asList("asdf",
                "java2s.com");
        System.out.println(isEmpty(collection));
    }//from   ww w . ja  v a  2 s .  com

    /**
     * Check if collection is null or empty.
     * @param collection The collection to check
     * @return true if collection is null or empty and false if isn't null <b>and</b> have one or more elements
     */
    public static final boolean isEmpty(Collection<?> collection) {
        return (collection == null || collection.isEmpty());
    }
}

Related Tutorials