In dart, Set
class has two different factory constructors Set.from()
and Set.of()
.
Their returned results are same of same type. Is there any use case difference between them ? How to decide which one to use ?
See output of this program:
void main() {
List<int> myList = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5];
Set<int> mySetFrom = Set.from(myList);
Set<int> mySetOf = Set.of(myList);
print("mySetFrom type: ${mySetFrom.runtimeType}");
print("mySetFrom: ${mySetFrom}");
print("mySetOf type: ${mySetOf.runtimeType}");
print("mySetOf: ${mySetOf}");
}
Output:
mySetFrom type: _CompactLinkedHashSet<int>
mySetFrom: {1, 2, 3, 4, 5}
mySetOf type: _CompactLinkedHashSet<int>
mySetOf: {1, 2, 3, 4, 5}