To find the union of two sets in Dart, you can use the union method provided by the Set class.
In this example,
set1
and set2
, containing some elements.set1
to perform the union operation with set2
.unionSet
contains all the unique elements from both set1
and set2
.var set1 = {1, 2, 3};
var set2 = {3, 4, 5};
var unionSet = set1.union(set2);
print("Union of set1 and set2:");
print(unionSet);
Union of set1 and set2: {1, 2, 3, 4, 5}
In this example,
set1
and set2
, containing some string elements.set1
to perform the union operation with set2
.unionSet
contains all the unique elements from both set1
and set2
.var set1 = {'apple', 'banana', 'orange'};
var set2 = {'orange', 'pear', 'grape'};
var unionSet = set1.union(set2);
print("Union of set1 and set2:");
print(unionSet);
Union of set1 and set2: {apple, banana, orange, pear, grape}
In this tutorial, we learned How to find Union of Two Sets in Dart language with well detailed examples.