title: indexOf in Java - ArrayList
body: <pre><code>import java.util.ArrayList;
  import java.util.Scanner;
  
  public class JavaApplication10Arraylistandobjects {
  
      static Scanner user_input = new Scanner(System.in);
  
      public static void main(String[] args) {
          test();
      }
  
      public static void test(){
          ArrayList&lt;mainclass&gt; me = new ArrayList &lt;&gt; ();
          mainclass ob;
          for (int i=0;i&lt;2;i++){
              ob = new mainclass();
              System.out.println("name");
              ob.name = user_input.nextLine();
              System.out.println("sname");
              ob.sname = user_input.nextLine();
              me.add(ob);
          }
          System.out.println("Show List: " + me);
          System.out.println("Confirm if is true or false: " + me.get(1).toString().contains("max"));
          System.out.println("what is index of: " + me.get(1).toString().indexOf("max"));
      }
  }
  </code></pre>
  
  <p>    </p>
  
  <pre><code>public class mainclass {
  
      public String getName() {
      return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getSname() {
          return sname;
      }
  
      public void setSname(String sname) {
          this.sname = sname;
      }
  
      @Override
      public String toString() {
          return "mainclass{" + "name=" + name + ", sname=" + sname + '}';
      }
  
      String name;
      String sname;
  }
  </code></pre>
  
  <p>My questions is how can I find correctly indexOf string.
  For example when I am checking if string "max" exist - it shows me "true"
   and when I am trying to find index of string "max" it shows me index  15 which is not correct.</p>
  
  <p>P.S. I found an article with the same problem where it says that I have to override equals and hashcode - I've done it but anyway I got the same problem.</p>
  
  <p>Please point me to the right direction.
  What I am doing wrong here, can someone explain me pls.</p>
  
  <p>These are my inputs and output.</p>
  
  <ul>
  <li>run: 
  name Jony 
  sname Bravo </li>
  </ul>
  
  <p>name max 
  sname hitman </p>
  
  <p>Show List:[mainclass{name=Jony, sname=Bravo}, mainclass{name=max, sname=hitman}] </p>
  
  <p>Confirm if is true or false: true 
  what is index of: 15</p>
  
  <p>BUILD SUCCESSFUL (total time: 11 seconds)</p>