title: Java : Create new ArrayLists based on some condition from existing ArrayList
body: <p>I am new to java .</p>
  
  <p>I have 2 ArrayLists of Strings </p>
  
  <pre><code>List&lt;String&gt; a= [2,14]
  List&lt;String&gt; b= [2,3,4,5]
  </code></pre>
  
  <p>I want two new ArrayLists </p>
  
  <p>1) List has the value which is in <code>b</code> but not in <code>a</code></p>
  
  <pre><code>  List&lt;String&gt; c= [3,4,5]
  </code></pre>
  
  <p>2) List has the value <code>a</code> but not in <code>b</code></p>
  
  <pre><code>  List&lt;String&gt; d=[14]
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>    List&lt;String&gt; c = new ArrayList&lt;String&gt;(b);
      c.removeAll(a);
     System.out.println("c::::::::::::::::::::::::::::::"+c);  // 2,3,4,5
  </code></pre>
  
  <p>which is not removing the values of List a</p>
  
  <p>Complete Code </p>
  
  <pre><code>   public static void updatePartyType(List&lt;String&gt; oldPartyKeys, List&lt;String&gt; newPartyKeys, String customerCode) {
     System.out.println("oldPartyKeys---&gt;"+oldPartyKeys);// 2,14
     System.out.println("newPartyKeys---&gt;"+newPartyKeys); // 2,3,4,5
  
     System.out.println("oldPartyKeys class ---&gt;"+oldPartyKeys.getClass());// class java.util.ArrayList
  
     List&lt;String&gt; newlySelectedPartyKeys = new ArrayList&lt;String&gt;(newPartyKeys);
     newlySelectedPartyKeys.removeAll(oldPartyKeys);
                      System.out.println("newlySelectedPartyKeys::::::::::::::::::::::::::::"+newlySelectedPartyKeys);
  </code></pre>