title: Java loop through arraylist and remove any objects of type item with a matching code
body: <p>I am trying to do a task of looping through an arraylist of objects of type item. Each item object has a code variable. If there is already an object with the code then it is removed from the list.</p>
  
  <p>Code:</p>
  
  <pre><code>//Search list for item based on code. 
  //If item with code is found, it is removed/deleted from the list. 
  //Else user is told "No item Found"
  
  public void deleteItem(String code)
  {
      boolean found = false;
  
      for(Item item : items)
      {
          if(item.getCode().equals(code))
          {
              found = true;
              items.remove(item);
          }
      }
  
      if(found)
      {
          System.out.println("Found and removed item with code: " + code);          
      }
      else
      {
         System.out.println("No item with code" + code + "found");
      }
  }
  </code></pre>
  
  <p>I get java.util.ConcurrentModificationException</p>
  
  <p>Any help please?</p>