Removes from this collection all of its elements that are not contained in the specified collection.
package com.logicbig.example.arraydeque;
import java.util.ArrayDeque;
import java.util.List;
import java.util.Set;
public class RetainAllExample2 {
public static void main(String... args) {
ArrayDeque<Integer> ad = new ArrayDeque<>(List.of(3, 8, 1, 9));
System.out.println(ad);
boolean b = ad.retainAll(Set.of(null));
System.out.println(b);
System.out.println(ad);
}
}
Output
Caused by: java.lang.NullPointerException
at java.base/java.util.Set.of(Set.java:693)
at com.logicbig.example.arraydeque.RetainAllExample2.main(RetainAllExample2.java:17)
... 6 more