To check if two lists are equal in Dart, you can use the equals
method or the ==
operator.
In this example,
list1
and list2
with initial values.equals
method to check if list1
equals list2
.void main() {
List<int> list1 = [1, 2, 3];
List<int> list2 = [1, 2, 3];
bool result = list1.equals(list2);
print('Are the lists equal? $result');
}
Are the lists equal? true
In this example,
list1
and list2
with initial values.==
operator to check if list1
equals list2
.void main() {
List<int> list1 = [1, 2, 3];
List<int> list2 = [1, 2, 3];
bool result = list1 == list2;
print('Are the lists equal? $result');
}
Are the lists equal? true
In this tutorial, we learned How to check if Two Lists are Equal in Dart language with well detailed examples.