I have two ArrayList objects with three integers each. I want to find a way to return the common elements of the two lists. Has anybody an idea how I can achiev
// Create two collections:
LinkedList listA = new LinkedList();
ArrayList listB = new ArrayList();
// Add some elements to listA:
listA.add("A");
listA.add("B");
listA.add("C");
listA.add("D");
// Add some elements to listB:
listB.add("A");
listB.add("B");
listB.add("C");
// use
List common = new ArrayList(listA);
// use common.retainAll
common.retainAll(listB);
System.out.println("The common collection is : " + common);