title: ArrayList contains method not work as I would expect?
body: <p>ArrayList use <code>equals()</code> in its <code>contains</code> method to see if provide object equals any item in the list as the document say: </p>
  
  <blockquote>
    <p>Returns true if this list contains the specified element. More
    formally, returns true if and only if this list contains at least one
    element e such that (o==null ? e==null : o.equals(e)). see <a href="https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#contains-java.lang.Object-" rel="nofollow noreferrer">this</a></p>
  </blockquote>
  
  <p>I have this class </p>
  
  <pre><code>class Foo
  {
    private String value;
    public Foo(String value)
    {
      this.value = value;
    }
  
    @Override
    public boolean equals(Object o)
    {
      return o == null ? this.value == null : o.toString().equals(this.value);
    }
  }
  </code></pre>
  
  <p>I want to use <code>contains</code> method to check if item exists like this</p>
  
  <pre><code>List&lt;Foo&gt; list = new ArrayList&lt;Foo&gt;();
  
  Foo item1 = new Foo("item1");
  Foo item2 = new Foo("item2");
  list.add(item1);
  list.add(item2);
  
  System.out.println(item1.equals("item1"));       //return true
  System.out.println(list.contains("item1"));      //false !! why?!
  </code></pre>
  
  <p>but <code>contains</code> method return <code>false</code> , while <code>item1.equals("item1")</code> return <code>true</code>. </p>
  
  <p>why <code>contains</code> return false when it use <code>equals</code> method for provided object</p>