Online Java Compiler By
JavaTpoint.com
import java.util.ArrayList; public class ArrayListRetainAllExample2 { ArrayList
numbers = null; System.out.println(numbers); // null ArrayList
retainedNumbers = new ArrayList<>(); retainedNumbers.add("1"); retainedNumbers.add("2"); System.out.println(retainedNumbers); // [1, 2] retainedNumbers.retainAll(numbers); // throw NullPointerException }
Output