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

Java examples for Collection Framework:Array Contain

Description

Generic method to check if an Item in ArrayList

Demo Code


//package com.java2s;
import java.util.ArrayList;

public class Main {
    public static <T> boolean inArrayList(ArrayList<? extends T> array,
            T other) {//from  w w  w  . j  a  v a 2  s. com
        for (T object : array) {
            if (object.equals(other)) {
                return true;
            }
        }

        return false;
    }
}

Related Tutorials