We would like to know how to retain Another Collection.
import java.util.ArrayList; import java.util.List; /* w w w . j a v a 2 s .co m*/ public class MainClass { public static void main(String args[]) throws Exception { List list = new ArrayList(); list.add("A"); list.add("A"); list.add("B"); list.add("B"); list.add("C"); list.add("C"); list.add("D"); List list2 = new ArrayList(); list2.add("A"); list2.add("B"); list2.add("C"); list.removeAll(list2); System.out.println(list); } }
The code above generates the following result.