title: Check if a collection contains an object, comparing by reference
body: <p>The <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html#contains%28java.lang.Object%29">Collection.contains()</a> method check if a collection contains a given object, using the <code>.equals()</code> method to perform the comparison.</p>
  
  <p>From Java7 Javadoc:</p>
  
  <blockquote>
    <p><strong>boolean contains(Object o)</strong></p>
    
    <p>Returns true if this collection contains
    the specified element. More formally, returns true if and only if this
    collection contains at least one element e such that (o==null ?
    e==null : o.equals(e)).</p>
  </blockquote>
  
  <p>Is there a smart way to check if a collection contains an object <code>o</code>, but comparing by reference instead (i.e. <code>o==e</code>)?</p>
  
  <p>Of course I can iterate through the collection and make the check, I'm looking for an existing function which can do that.</p>
  
  <p><strong>Clarifications:</strong></p>
  
  <ul>
  <li>I want to perform this operation <em>regardless</em> the <code>equals()</code> implementation of the object in the collection.</li>
  <li>I don't want to change the objects in the collection nor the collection itself.</li>
  </ul>
  
  <p><strong>Edit:</strong></p>
  
  <p>Even though my question is about a general solution for <code>Collection</code> implementations, specific cases for <code>Collection</code> sub-interfaces would also be appreciated.</p>