To check if a list contains all the elements of another list in Dart, you can use the containsAll
method.
In this example,
list1
and list2
with different values.containsAll
method of list1
to check if it contains all elements of list2
.containsAll
method returns true
if all elements of list2
are present in list1
; otherwise, it returns false
.void main() {
List<int> list1 = [1, 2, 3, 4, 5];
List<int> list2 = [2, 4];
bool result = list1.containsAll(list2);
print("List 1 contains all elements of List 2: \$result");
}
List 1 contains all elements of List 2: true
In this example,
list1
and list2
with different values.containsAll
method of list1
to check if it contains all elements of list2
.containsAll
method returns true
if all elements of list2
are present in list1
; otherwise, it returns false
.void main() {
List<int> list1 = [1, 2, 3, 4, 5];
List<int> list2 = [2, 4, 6];
bool result = list1.containsAll(list2);
print("List 1 contains all elements of List 2: \$result");
}
List 1 contains all elements of List 2: false
In this tutorial, we learned How to check if a List contains all the elements of Another List in Dart language with well detailed examples.