I have two lists [1,2,3,4,5,6,7]
and [3,5,6,7,9,10]
. I want to get the difference of the first list and the second list.
The expected output would be [1,2,4]
since those are the only elements in only list 1 and not list 2.
I'm using Flutter and Dart. I looked this up on the internet, I know it seems like a simple question but I couldn't find anything.
Should be irrelevant but I'm using publishing for iOS
I'd prefer an answer without just a foreach loop, im looking to see if there is a library for it.
here == operator the instance of the list not the content, where are equals method compare the data inside lists. List<String>list3=list1; print(list1==list3);
A very commonly used collection in programming is an array. Dart represents arrays in the form of List objects. A List is simply an ordered group of objects. The dart:core library provides the List class that enables creation and manipulation of lists.
Simple & Recommended Way to do this is
var a = [1,2,3,4,5];
var b = [1,2];
a.removeWhere((element) => b.contains(element));
print(a); //[3, 4, 5]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With