Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,894 questions

51,825 answers

573 users

How to check if two lists are equal in Dart

3 Answers

0 votes
bool ListsEqual(var list1, var list2) {
    if (!(list1 is List && list2 is List)
        || list1.length != list2.length) {
        return false;
    }
     
    for (int i = 0; i < list1.length; i++) {
        if (list1[i] != list2[i]) {
            return false;
        }
    }
     
    return true;
}
 
void main() {
    List list1 = [2, 0, 4, 8, 1, 6];
    List list2 = [2, 0, 4, 8, 1, 6];

    if (ListsEqual(list1, list2)) {
        print('yes');
    } else {
        print('no');
    }
}
 
 
 
 
 
/*
run:
 
yes
 
*/

 



answered Oct 14, 2022 by avibootz
0 votes
import 'package:collection/collection.dart';

void main() {
    List list1 = [2, 0, 4, 8, 1, 6];
    List list2 = [2, 0, 4, 8, 1, 6];

    Function equality = const ListEquality().equals;
  
    print(equality(list1, list2)); 
}
 
 
 
 
 
/*
run:
 
true
 
*/

 



answered Oct 14, 2022 by avibootz
0 votes
import 'package:collection/collection.dart';

void main() {
    List list1 = [1, 8, 0, 6, 2, 4];
    List list2 = [2, 0, 4, 8, 1, 6];
 
    Function unordered_deep_equality = const DeepCollectionEquality.unordered().equals;
  
    print(unordered_deep_equality(list1, list2)); 
}
 
 
 
 
 
/*
run:
 
true
 
*/

 



answered Oct 14, 2022 by avibootz

Related questions

2 answers 171 views
1 answer 92 views
92 views asked Oct 14, 2022 by avibootz
1 answer 160 views
1 answer 146 views
146 views asked May 6, 2020 by avibootz
...