Generic method to check if an Item in Array - Java Collection Framework

Java examples for Collection Framework:Array Contain

Description

Generic method to check if an Item in Array

Demo Code


//package com.java2s;

public class Main {
    public static <T> boolean inArray(T[] array, T other) {
        for (Object object : array) {
            if (object.equals(other)) {
                return true;
            }/*  w w w .  j av  a2s . com*/
        }

        return false;
    }
}

Related Tutorials