集册 Java实例教程 检查空值上的数组。

检查空值上的数组。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

440
检查空值上的数组。


//package com.book2s;

/**
nowjava - 时  代  Java 提供 
**/

public class Main {

    /**

     * 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;

    }

}