Java Array Equal equalsAny(T element, T[] array)

Here you can find the source of equalsAny(T element, T[] array)

Description

equalsAny compares a given element with all elements of a given array.

License

Open Source License

Parameter

Parameter Description
element the element to look for
array the array to look over
T COMMENT

Return

true if there is an element in the array, that is equal to the given element, false otherwise

Declaration

public static <T> boolean equalsAny(T element, T[] array) 

Method Source Code


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

import java.util.List;

public class Main {
    /**/* ww  w . j a  va 2s  . co m*/
     * equalsAny compares a given element with all elements of a given array.
     *  If an array element is equal to the given element {@code true} is
     *  returned, otherwise the return value is {@code false}.
     * 
     * @param element the element to look for
     * @param array the array to look over
     * 
     * @return {@code true} if there is an element in the array, that is
     *  equal to the given element, {@code false} otherwise
     * 
     * @param <T> COMMENT
     */
    public static <T> boolean equalsAny(T element, T[] array) {
        for (T e : array)
            if (e.equals(element))
                return true;
        return false;
    }

    /**
     * equalsAny compares a given element with all elements of a given list.
     *  If a list element is equal to the given element {@code true} is
     *  returned, otherwise the return value is {@code false}.
     * 
     * @param element the element to look for
     * @param list the list to look over
     * 
     * @return {@code true} if there is an element in the list, that is
     *  equal to the given element, {@code false} otherwise
     * 
     * @param <T> COMMENT
     */
    public static <T> boolean equalsAny(T element, List<T> list) {
        for (T e : list)
            if (e.equals(element))
                return true;
        return false;
    }
}

Related

  1. equals(Object array1, Object array2)
  2. equals(Object[] objs1, Object[] objs2)
  3. equals(String[] fullSet, String[] subSet)
  4. equals(T[] array1, T[] array2)
  5. equals3(double[][][] arr1, double[][][] arr2)
  6. equalsIgnoreSequence(final T[] array1, final T[] array2)
  7. equalsIgnoreSequence(Object[] array1, Object[] array2)
  8. equalsToElement(final Object[] arr, final Object obj)
  9. equalStringArrays(String[] expected, String[] actual)