title: java.lang.indexOutOfBound using arraylist
body: <p>Question: Why am I getting an IndexoutOfBound error?</p>
  
  <p>Background: I am writing a store app. Using a List ArrayList to store all of items passed in through a CSV file. I wrote a product obj and it is being populated correctly. I am using a cart obj I wrote to iterate though this product list to perform add and remove methods on a separate cart ArrayList. For some reason I am getting a java.lang.IndexOutOfBound error when I compare user input to the name attribute of my product object. For this I am using the .equals method from the string class.</p>
  
  <p>Code Below: This is my performAdd private method for my cart object. It promts the user for a string input and then uses that to find a specific element in my list to perform the add to my local cartList. It also removes that element from the orginal list. </p>
  
  <pre><code>private boolean performAdd(Inventory inventory){
  
          // return value
          boolean success = false;
  
          Scanner in = new Scanner(System.in);
  
          System.out.println("Please provide the name of the item you would like to add to the cart");
          String temp = in.nextLine();
  
           System.out.println(temp);
  
          Iterator itr = inventory.productList.iterator();
  
          // empty product object using default
          Product prod = new Product();
  
          int i = 0; // index values for grabbing objects from the inventory list
  
          // looping through the array list of our inventory of items
           while (itr.hasNext()){
  
               // check to see which product has the same name as what the user said 
               if (temp.equals(inventory.productList.get(i).getName())){
  
                   prod = inventory.productList.get(i); // grab the product object from inventory list and assign empty product object
  
                   inventory.productList.remove(i); // remove this object from the inventory list
  
                   addToCart(prod); // call to in class method for cart
  
                   success = true; // change boolean return value
                  }
  
               i++; // increment index 
           }
          return success;
      }
  </code></pre>