集册 Java实例教程 检查数组中的项的泛型方法

检查数组中的项的泛型方法

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

425
检查数组中的项的泛型方法


//package com.nowjava;
/**来自 
 n o w j a v a . c o m**/


public class Main {

    public static <T> boolean inArray(T[] array, T other) {

        for (Object object : array) {

            if (object.equals(other)) {

                return true;

            }

        }


        return false;

    }

}