Online Java Compiler By
JavaTpoint.com
import java.util.ArrayDeque; import java.util.Collection; public class JavaCollectionRetainAllExample3 { public static void main(String[] args) { Collection
collection=new ArrayDeque<>(); collection.add("Himanshu"); collection.add("Sham"); collection.add("Rita"); Collection
collection1=new ArrayDeque<>(); //it will give an exception as it do not support null elements. collection1.retainAll(null); System.out.println(collection.containsAll(collection1)); } }
Output