import java.util.*;
public class LinkeListOper5 {
public static void main(String args[]) {
LinkedList<String> list1 = new LinkedList<>();
list1.add("john");
list1.add("kiyan");
list1.add("kayna");
list1.add("cristy");
System.out.println("Before retaining the list1 is : " + list1);
LinkedList<String> list2 = new LinkedList<>();
list2.add("kiyan");
list2.add("cristy");
list2.add("rahul");
System.out.println("Before retaining the list2 is : " + list2);
//this function will copy the common elements of list1 and list2
list1.retainAll(list2);
System.out.println("Afte retaining the list is : " + list1);
}
}