title: Out of Bounds Exception using ArrayList
body: <p>Im not sure why I am getting an out of bounds exception, can someone please help, this is really annoying me as I really want to understand what is happening.</p>
  
  <p>public class LoyaltyCardList
  {
      private ArrayList  loyaltyCards; </p>
  
  <pre><code>/**
   * 
   */
  public LoyaltyCardList()
  {
      loyaltyCards = new ArrayList &lt;LoyaltyCard&gt; ();
  }
  
  /**
   * 
   */
  public void addLoyaltyCard(LoyaltyCard newLoyaltyCard)
  {
      loyaltyCards.add(newLoyaltyCard);
  }
  
  public void getAllLoyaltyCards()
  {
      int index = 0;
      while(index &lt;= getNumberOfLoyaltyCards())
      {
          loyaltyCards.get(index).printCustomerDetails();
          index++;
      }
  }
  
  public void getLoyaltyCard(int LoyaltyCardEntry)
  {
      if(LoyaltyCardEntry &lt; 0)
      {
          System.out.println("Negative Entry: " +LoyaltyCardEntry);
      }
      else if(LoyaltyCardEntry &lt; getNumberOfLoyaltyCards())
      {
          loyaltyCards.get(LoyaltyCardEntry).printCustomerDetails();
      }
      else
      {
          System.out.println("No Such Entry:" + LoyaltyCardEntry);
      }
  }
  
  public int getNumberOfLoyaltyCards()
  {
      return loyaltyCards.size();
  }
  </code></pre>