Checks an array on null value. - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

Checks an array on null value.

Demo Code


//package com.book2s;

public class Main {
    /**// w  w  w  .j a  v a 2 s. co m
     * Checks an array on {@code null} value.
     *
     * @param array the checked array.
     * @param <T> the element type of checked array.
     * @return {@code true} if the array contains {@code null}.
     */
    public static <T> boolean hasNull(T[] array) {
        for (T item : array) {
            if (item == null) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials