Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dart: I want to check if the contents of 2 Lists are the same

One List is a List<String>? and the other is a List<dynamic>

I’d prefer not to change these data types. I just want to check if the contents are the same.

If I have a List [1, 2, 3] and a List [1, 2, 3] the output of a bool should be true

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If I have a List [1, 2, 3] and a List [1, 3, 2] the output of a bool should be true

If I have a List [1, 2, 4] and a List [1, 2, 3] the output of a bool should be false

>Solution :

I will sort in this case and check equal like

final e1 = [1, 2, 3]..sort();
final e2 = [1, 3, 2]..sort();

print(e1.equals(e2)); //true
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading