title: Listing Common elements in Java
body: <p>I'm trying to printout the common elements between two lists and when I try to use retainAll(); it basically skips over everything past that. </p>
  
  <pre><code>    List&lt;String&gt; dblist = Arrays.asList(db);
      List&lt;String&gt; medlist = Arrays.asList(medication);
  
      //Get Meds in Database that Match Patient Meds 
      jTextArea3.append("\nMedications in dblist :"+"\n");
      for (int d =0; d&lt;dblist.size(); d++){
          jTextArea3.append(dblist.get(d)+"\n");
      }       
  
      jTextArea3.append("\nMedications in medlist :"+"\n");
      for (int d =0; d&lt;medlist.size(); d++){
          jTextArea3.append(medlist.get(d)+"\n");
      }    
  
      //dblist.retainAll(medlist);
      jTextArea3.append("\nMedications in both :"+"\n");
      for (int d =0; d&lt;dblist.size(); d++){
          jTextArea3.append(dblist.get(d)+"\n");
      } 
  </code></pre>
  
  <p>This will list out the contents of dblist.get(d) but as soon as I uncomment dblist.retainAll(medlist) the output stops at the end of the medlist output above. </p>