Home > Software design >  Is it possible to remove duplicates in Dart with another variable
Is it possible to remove duplicates in Dart with another variable

Time:12-31

I have searched a lot for removing duplicates from a list in Dart using ANOTHER variable.

Here is what I mean:

List<int> numbers = [1, 2, 3, 4];

// This list has 4 new elements than the first one
List<int> moreNumbers = [1, 2, 3, 4, 5, 6, 7, 8];

// Now I want to push the moreNumbers unique elements to the numbers one

I want to push it so the end result for the numbers variable should be:

[1, 2, 3, 4, 5, 6, 7, 8];

Is it possible?

CodePudding user response:

void main() {
      var lst = [1,2,3,4];
      var lst2 = [1,2,3,4,5,6,7,8];
      var s = {...(lst lst2)};

print(s.toList()); }

  •  Tags:  
  • dart
  • Related