title: Dynamically removing elements from List
body: <p>I am having an issue removing elements of a list while iterating through the list. Code:</p>
  
  <pre><code>For (WebElement element: list){
      if (!element.isEnabled() || !element.isSelected()){
          list.remove(element);
      }
  }
  </code></pre>
  
  <p>I get a <code>ConcurrentModificationException</code>, which I totally understand. I am removing an item from a list while in the loop that goes through the list. Intuitively, that would screw up the indexing of the loop.</p>
  
  <p>My question is, how else should I remove elements that are either not <code>enabled</code> or <code>selected</code> from this list?</p>