Here you can find the source of containsInstance(Collection collection, Object element)
Parameter | Description |
---|---|
collection | the Collection to check |
element | the element to look for |
public static boolean containsInstance(Collection collection, Object element)
//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; } }