title: Java ArrayList with object in a loop
body: <p>How do I know the name of the object in the <code>ArrayList</code> when it is declared in a loop?
  I can get it by an index but I don't know the name of it to locate/know if it is in the <code>ArrayList</code>.</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class Teste {
  
      public static void main(String[] args) {
          ArrayList&lt;UserClasss&gt; userList = new ArrayList&lt;UserClasss&gt;();
  
          for (int i = 0; i &lt; 5; i++) {
              UserClasss user = new UserClasss();
              user.setName("name"+i);
              user.setAge((int)(Math.random()*80));
              userList.add(user);
          }
          for (UserClasss forUser:userList){
              System.out.println(forUser.getName());
              System.out.println(forUser.getAge());
          }
  
  
          //how can i know if contains it here?
          //userList.contains(user);
          //and how do i know the index of it?
          //userList.indexOf(user);
  
  
      }
  }
  
  class UserClasss {
  
      private String name;
      private int age;
  
      public void setName(String s){
          name = s;
      }
      public String getName(){
          return name;
      }
      public void setAge(int i){
          age = i;
      }
      public int getAge(){
          return age;
      }
  }
  </code></pre>