Online Java Compiler By
JavaTpoint.com
import java.util.LinkedList; import java.util.List; public class JavaListContainsAllExample1 { public static void main(String[] args) { List
list= new LinkedList<>(); for (int i=0;i<11;i++){ list.add(i); } System.out.println("Total elements in the list : "+list); List
list1= new LinkedList<>(); for (int i=0;i<11;i++){ if(i%2==0) { list1.add(i); } } //returns true, if this list contains all the elements of list1. Boolean bool=list.containsAll(list1); if (bool) { System.out.println("Contains All method will return " + bool); } else{ System.out.println("Contains All method will return " + bool); } } }
Output