Java Array Contain arrayContains(T[] src, T target)

Here you can find the source of arrayContains(T[] src, T target)

Description

Linear-search implementation, uses CollectionHelper#search(Object[],Object) .

License

Open Source License

Return

True if target is included in the source array.

Declaration

public static <T> boolean arrayContains(T[] src, T target) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   ww w  . j  ava2s . co m*/
     * Linear-search implementation, uses {@link CollectionHelper#search(Object[], Object)}.
     * @return True if target is included in the source array.
     */
    public static <T> boolean arrayContains(T[] src, T target) {
        return search(src, target) != -1;
    }

    /**
     * Linear-search implementation.
     */
    public static <T> int search(T[] src, T target) {
        for (int i = 0; i < src.length; i++) {
            if (src[i].equals(target))
                return i;
        }
        return -1;
    }
}

Related

  1. arrayContains(T haystack[], T needle)
  2. arrayContains(T search, T[] array, boolean def)
  3. arrayContains(T[] arr, T item)
  4. arrayContains(T[] array, T value)
  5. arrayContains(T[] source, T[] target)
  6. arrayContains(T[] ts, T t)
  7. arrayContains1(String[] parent, String[] child)
  8. arrayContainsElement(T[] array, T element)
  9. arrayContainsEntry(T[] array, T entry)