Java Array Contain arrayContains(T[] arr, T item)

Here you can find the source of arrayContains(T[] arr, T item)

Description

Determines if a array of any type contains the given item.

License

Open Source License

Parameter

Parameter Description
T The type being compared to.
arr The array being checked for a element.
item The item to check for.

Return

True if the array contains the specified element.

Declaration

public static <T> boolean arrayContains(T[] arr, T item) 

Method Source Code

//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;
    }
}

Related

  1. arrayContains(String[] parent, String[] child)
  2. arrayContains(String[] pArray, String pItem)
  3. ArrayContains(String[][] arr, String s)
  4. arrayContains(T haystack[], T needle)
  5. arrayContains(T search, T[] array, boolean def)
  6. arrayContains(T[] array, T value)
  7. arrayContains(T[] source, T[] target)
  8. arrayContains(T[] src, T target)
  9. arrayContains(T[] ts, T t)