检查两个列表的相等性 如何检查它们的两个元素是否相等,而不是在索引方面

check equality of two list how to check the elements of both them are equal not in index wise

提问人:Akhilesh ms 提问时间:9/13/2022 最后编辑:Ravindra S. PatilAkhilesh ms 更新时间:9/13/2022 访问量:122

问:

list1=["hello World","hello India"]

list2=["hello India","hello world"]

我怎样才能检查这两个列表的相等性

Flutter 列表 DART 相等

评论

3赞 Thiago Fontes 9/13/2022
这回答了你的问题吗?如何在 Dart 中比较列表的平等性?

答:

-1赞 Ravindra S. Patil 9/13/2022 #1

尝试以下代码引用集合

导入 'package:collection/collection.dart';

void main() {
  List list1 = ["hello World", "hello India"]; 
  List list2 = ["hello India", "hello world"];

  print(ListEquality().equals(list1, list2));
}

结果 - false

2赞 Ivo 9/13/2022 #2

您可以尝试比较列表的排序副本,例如

import 'package:collection/collection.dart';

void main() {
  var list1 = ["hello world","hello India"];
  var list2 = ["hello India", "hello world"];

  print(ListEquality().equals(list1.toList()..sort(), list2.toList()..sort()));
}