Dart – Set Length
To get the length of a Set in Dart, read its length
property. length
property is read-only and returns an integer representing the number of elements in the Set.
Syntax
The syntax to read length
property of a Set set
is
</>
Copy
set.length
Example
In this example, we take a Set of strings fruits
and find the length of this Set programmatically using Set.length
property.
main.dart
</>
Copy
void main() {
var fruits = {'apple', 'banana', 'cherry'};
var len = fruits.length;
print('Length of given Set : $len');
}
Output
Length of given Set : 3
Conclusion
In this Dart Tutorial, we learned how to get the length of a Set, with examples.