Check if Collection has Elements - Java java.util

Java examples for java.util:Collection Element

Description

Check if Collection has Elements

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(hasElements(collection));
    }/*from  ww  w. ja  v a 2s .c o m*/

    public static boolean hasElements(Collection<?> collection) {
        return collection != null && !collection.isEmpty();
    }
}

Related Tutorials