title: How to compare 2 lists and return a list of the greatest subset?
body: <p>I want to compare two ArrayLists and return the greatest subset of similarities in Java. So I want to compare parts of the list not just single values.</p>
  
  <p>Example:</p>
  
  <pre><code>list 1       list 2
  F            A
  A            B
  B            C
  C            F
  D            D
  Z            Z
  A
  F
  C
  </code></pre>
  
  <p>greatest subset:</p>
  
  <pre><code>Arraylist: [A,B,C]
  </code></pre>
  
  <p>The second greatest subset should be:</p>
  
  <pre><code>ArrayList: [D,Z]
  </code></pre>
  
  <p>How can I do this efficiently?(without using more than 2 for loops)</p>
  
  <p>retainAll() doesn't work, retainAll() returns the equal values, not the largest subset.</p>
  
  <p><strong>Edit</strong>
  I want as output, List before greatest subset, greatest subset, list after greatest subset. By the example the output should be:</p>
  
  <pre><code>[[F],[null]],[A,B,C],[[D,Z,A,F,C],[F,D,Z]]
  </code></pre>