title: How to remove item in List?
body: <p>I have two List in nest for loop, When I matched a item in inner, I want to remove it so that performance will up.</p>
  
  <pre><code>List&lt;String[]&gt; brandList = readCsvFile("/tmp/brand.csv");
  List&lt;String[]&gt; themeList = readCsvFile("/tmp/theme.csv");
  
  for (String[] brand : brandList) {
      for (String[] theme : themeList) {
          if (brand[0].equals(theme[0])) {
              themeList.remove(theme);
          }
      }
  }
  </code></pre>
  
  <p>I got a <code>java.util.ConcurrentModificationException</code> error. If I changed to CopyOnWriteArrayList, The error as below:</p>
  
  <pre><code>CopyOnWriteArrayList&lt;String[]&gt; themeList = (CopyOnWriteArrayList&lt;String[]&gt;)readCsvFile("/tmp/theme.csv");
  
  java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.concurrent.CopyOnWriteArrayList
  </code></pre>
  
  <p>Now how can I do? omit remove? or anyway else?</p>
  
  <p>I think this is what I need:</p>
  
  <pre><code>List&lt;String[]&gt; brandList = readCsvFile("/tmp/brand.csv");
  List&lt;String[]&gt; themeList = readCsvFile("/tmp/theme.csv");
  
  for (String[] brand : brandList) {
      List&lt;String[]&gt; toRemove = new ArrayList&lt;String[]&gt;();
  
      for (String[] theme : themeList) {
          if (brand[0].equals(theme[0])) {
              toRemove.add(theme);
          }
      }
  
      for (String[] theme : toRemove) {
          themeList.removeAll(theme);
      }
  }
  </code></pre>