title: Remove an item from List
body: <p>i am removing an Student object from ArrayList of Students, this is my code, below is the Student.java</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package corejava.list;
  
  /**
   * 
   * @author Rahul 
   */
  
  public class Student {
  private int id;
  private String name;
  
  public Student(int id,String name){
      this.id = id;
      this.name = name;
  }
  
  public Student(int id){
      this.id = id;        
  }
  
  @Override
  public int hashCode(){
      return this.getId() * 37;
  }
  
  @Override
  public String toString(){
      StringBuffer strb = new StringBuffer();
      strb.append("\tID : ").append(this.getId()).append(", NAME : ").append(this.getName());
      return strb.toString();
  }
  
  @Override
  public boolean equals(Object studentOne){
      Student student = (Student) studentOne;
      boolean flag = false;
      if(this.getId() == student.getId()){
          flag = true;
      }
      return flag;
  }
  
  /**
   * @return the id
   */
  public int getId() {
      return id;
  }
  
  /**
   * @return the name
   */
  public String getName() {
      return name;
  }
  }
  </code></pre>
  
  <p>This is my Class which has a main method,</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package corejava.list;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  /**
   * 
   * @author Rahul
   */
  
  
  
  public class RemoveList {
      public static void main(String [] args){
          List&lt;Student&gt; studentList = null;
          try{
          studentList = new ArrayList&lt;Student&gt;(){{
              add(new Student(12,"Tom"));
              add(new Student(14, "Jack"));
              add(new Student(15, "Julean"));
              add(new Student(16, "Doughlas"));                
              add(new Student(17, "Bathsheba"));
          }};
  
          for(Iterator&lt;Student&gt; itr = studentList.iterator(); itr.hasNext();){
              System.out.println(itr.next());
          }
  
          System.out.println(studentList.remove(new Student(12)));
  
          for(Iterator&lt;Student&gt; itr = studentList.iterator(); itr.hasNext();){
              System.out.println(itr.next());
          }
  
      }catch(Exception e){
          e.printStackTrace();
      }
  }
  }
  </code></pre>
  
  <p>Now my question is, is it safe removing an item from ArrayList as i have done in the above code,</p>
  
  <p>does hashCode() plays a role in removing of the Student object from Collection,</p>
  
  <p>Do we have a better approach,</p>