Android Collection Contains 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.

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;

import java.util.Collection;

public class Main {
    /**//from   ww w.  j a v  a 2 s .  co  m
     * 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. contains(Collection collection, T value)
  2. containsInstance(Collection collection, Object element)