Java Collection Contain containsInstance(Collection collection, Object element)

Here you can find the source of containsInstance(Collection collection, Object element)

Description

Check whether the given Collection contains the given element instance.

License

Open Source License

Parameter

Parameter Description
collection the Collection to check
element the element to look for

Return

true if found, false else

Declaration

public static boolean containsInstance(Collection collection, Object element) 

Method Source Code

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

import java.util.*;

public class Main {
    /**//from w w  w .j  a  v  a  2  s  .c  om
     * Check whether the given Collection contains the given element instance.
     * <p>Enforces the given instance to be present, rather than returning
     * {@code true} for an equal element as well.
     *
     * @param collection the Collection to check
     * @param element    the element to look for
     * @return {@code true} if found, {@code false} else
     */
    public static boolean containsInstance(Collection collection, Object element) {
        if (collection != null) {
            for (Object candidate : collection) {
                if (candidate == element) {
                    return true;
                }
            }
        }
        return false;
    }
}

Related

  1. containsIgnoreCase(Collection collection, String value)
  2. containsIgnoreCase(Collection l, String s)
  3. containsIgnoreCase(String searchedWord, Collection words)
  4. containsIgnoreCase4Collections(Collection c, String s)
  5. containsInstance(Collection collection, Object element)
  6. containsInstanceOf(Collection collection, Class c)
  7. containsKey(Collection keys, String key)
  8. containsNo(Collection baseList, Collection valueList)
  9. containsNone(Collection container, Collection other)