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

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

Leave a Reply