ListIn this example, we compare two lists `list1` and `list2`. The `containsAll` method of `list1` is used to check if all elements of `list2` are present in it. The `containsAll` method is a default method of the `java.util.List` interface, which can be found in the `java.util` package library. Overall, the `containsAll` method is handy if you need to compare two lists, and it can be used with any implementation of the `List` interface in Java.
list1 = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); List list2 = new ArrayList<>(Arrays.asList(2, 3, 4)); boolean result = list1.containsAll(list2); System.out.println(result); // Output is true because list2 is a subset of list1.