Here you can find the source of arrayContains(T[] arr, T item)
Parameter | Description |
---|---|
T | The type being compared to. |
arr | The array being checked for a element. |
item | The item to check for. |
public static <T> boolean arrayContains(T[] arr, T item)
//package com.java2s; public class Main { /** Determines if a array of any type contains the given item. Comparison is done with * the {@link Object}'s equals(Object) method. This is especially helpful * to do with message splitting.//from ww w .j a v a2s . c o m * @param <T> The type being compared to. * @param arr The array being checked for a element. * @param item The item to check for. * @return True if the array contains the specified element. */ public static <T> boolean arrayContains(T[] arr, T item) { for (T t : arr) { if (t.equals(item)) { return true; } } return false; } }