title: Compare a string value with arraylist<object>
body: <p>I have a class of persons.</p>
  <pre><code>Public class Person{
  
  private String name = &quot;&quot;;
  
      public Person(String name) {
          
          this.name = name;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
      
  }
  </code></pre>
  <p>Now I have another class and inside the class I declared an arraylist</p>
  <pre><code>public class AddPerson {
  public ArrayList&lt;Person&gt; pers = new ArrayList&lt;Person&gt;();
  
  //here we add some persons to the arraylist
  pers.add(new Person(&quot;Simon&quot;));
  pers.add(new Person(&quot;Oscar&quot;));
  pers.add(new Person(&quot;Alfred&quot;));
  
  String name = &quot;Simon&quot;;
  pers.contains(name); //return false
  pers.equals(name); //return false 
  
  //I also want to be able to return the value and index of the name in arraylist if it exsists.
  if(pers.contains(name)) //return index and value
  }
  </code></pre>
  <p>When I try to check if two strings are equal or if a string is already in my list I get both false. I did some research and I saw that I need to override my equals method (and mabey hash and contains method as well). I do not know how to do it and I could not find a good reference how to do it. Please help me to achive that.</p>