title: Error in removing object from ArrayList in Java [Eclipse]
body: <p>I have this method that removes a specific Object <strong>P</strong> from the ArrayList</p>
  
  <p>here is my code:</p>
  
  <pre><code>public void removeProduct(Product p) throws StockException{
          int flag=0;
          for(Product i:StockProducts)
              if(p.getCode()==i.getCode()){
                  this.StockProducts.remove(p);
                  flag=1;
              }
  
          if(flag==0){
                  StockException e = new StockException("could not remove the Product , PRODUCT IS NOT IN THE STOCK:  ", p);
          throw e;
            }
      }
  </code></pre>
  
  <p>Error :</p>
  
  <pre><code>Exception in thread "main" java.util.ConcurrentModificationException
      at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
      at java.util.ArrayList$Itr.next(Unknown Source)
      at Stock.removeProduct(Stock.java:29)
      at Test.main(Test.java:18)
  </code></pre>
  
  <p>If you need further information about my code tell me</p>
  
  <p><strong>ADDING METHOD</strong></p>
  
  <pre><code>public void addProduct(Product p) throws StockException{
          for(Product i:StockProducts)
              if(p.getCode()==i.getCode()){
                          StockException e = new StockException("could not add the Product , CODE ALREADY EXIST IN STOCK: ", p);
                  throw e;
                      }
  
                      this.StockProducts.add(p);  
      }
  </code></pre>