To create a set of size N in Dart, you can use the Set
class with initial elements.
In this example,
stringSet
using the Set
class and initialize it with initial string elements.length
property.void main() {
var stringSet = Set<String>.from(["apple", "banana", "cherry"]);
print("Size of stringSet: ${stringSet.length}");
}
Size of stringSet: N
In this example,
intSet
using the Set
class and initialize it with initial integer elements.length
property.void main() {
var intSet = Set<int>.from([1, 2, 3]);
print("Size of intSet: ${intSet.length}");
}
Size of intSet: N
In this tutorial, we learned How to create a Set of size N in Dart language with well detailed examples.