Check that an array only contains elements that are not null. - Java Collection Framework

Java examples for Collection Framework:Array Contain

Description

Check that an array only contains elements that are not null.

Demo Code


//package com.java2s;

public class Main {


    /**//from  w w  w .  ja v a2s .c om
     * Check that an array only contains elements that are not null.
     * @param values, can't be null
     * @return
     */
    public static boolean containsOnlyNotNull(Object... values) {
        for (Object o : values) {
            if (o == null) {
                return false;
            }
        }
        return true;
    }
}

Related Tutorials