How to Check If 2 Lists are Equal in Dart?

A List is a collection of elements, where each element is identified by an index. The List type represents a sequence of values, where each value can be accessed using its corresponding index. Lists are created using the [] operator, and the elements in the list are separated by commas. Lists can be initialized with any type of data, including null values.

The == operator can be used to compare two values of 2 variables for equality. However, this doesn’t work with List.

import 'package:flutter/foundation.dart';

List<int> list1 = [0, 3, 6, 9];
List<int> list2 = [0, 3, 6, 9];
print(listEquals(list1, list2)); //true

List<int> list1 = [0, 3, 6, 9];
List<int> list2 = [3, 0, 6, 9];
print(listEquals(list1, list2)); //false

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.