title: Java ArrayList - Find Item - Do I need Hash?
body: <p>Im learning Java and having a problem with ArrayList. I have read the Java doc and am thinking I maybe need to do the hash thing?</p>
  
  <p>I have an object called catalogue which has an array list of objects created from another class called item. Each item has fields for size, colour, price, product code,  (these are item attributes). I need to include a method in catalogue which accepts a product code and searches through the ArrayList to find the object with matching product code. And then returns that product.
  I have a toString method in my item class which lists all of the fields &amp; their values when called. Maybe that is what should be returned when the matching product code is found in array list?</p>
  
  <pre><code>import java.util.ArrayList;
  
  
  public class Catalogue
  {
  
     private ArrayList&lt;Item&gt; catalogue;
  
  
      public Catalogue ()
      { 
  
        catalogue = new ArrayList&lt;Item&gt;();
  
      }
  
      public void findItem(int code)
      {
          if(Item.code == prodcode){
  
          }
          else{
              System.out.println(catalogue.get(item));
  
          }
      }
  </code></pre>
  
  <p>I looked at Java doc and I read about hash and maybe its better for me to use that rather than iterator? I'm not sure which route to take. My code is half finished
  Any help greatly appreciated.
  Thankls</p>