Akhilesh ms
Akhilesh ms

Reputation: 35

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

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

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

how could I check equality of this two list

Upvotes: 2

Views: 168

Answers (2)

Ivo
Ivo

Reputation: 23134

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

Upvotes: 2

Ravindra S. Patil
Ravindra S. Patil

Reputation: 14775

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

Upvotes: -1

Related Questions