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

Time:09-13

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

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

how could I check equality of this two list

CodePudding user response:

You can try compare sorted copies of the lists, like

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()));
}

CodePudding user response:

Try below code refer collection

import 'package:collection/collection.dart';

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

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

Result - false

  • Related