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